<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<title>jQuery实现IE浏览器兼容placeholder效果</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
} .input {
width: 200px;
height: 30px;
line-height: 30px;
padding: 0 10px;
border: 1px solid #ddd;
margin: 20px auto;
display: block;
}
</style>
</head> <body>
<input type="text" placeholder="请输入姓名" class="input" />
<script src="http://apps.bdimg.com/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() { //判断浏览器是否支持placeholder属性
supportPlaceholder = 'placeholder' in document.createElement('input'), placeholder = function(input) { var text = input.attr('placeholder'),
defaultValue = input.defaultValue; if (!defaultValue) { input.val(text).addClass("phcolor");
} input.focus(function() { if (input.val() == text) { $(this).val("");
}
}); input.blur(function() { if (input.val() == "") { $(this).val(text).addClass("phcolor");
}
}); //输入的字符不为灰色
input.keydown(function() { $(this).removeClass("phcolor");
});
}; //当浏览器不支持placeholder属性时,调用placeholder函数
if (!supportPlaceholder) { $('input').each(function() { text = $(this).attr("placeholder"); if ($(this).attr("type") == "text") { placeholder($(this));
}
});
} });
</script>
</body> </html>

效果图:

jQuery实现ie浏览器兼容placeholder效果的更多相关文章

  1. 【jquery】基于 jquery 实现 ie 浏览器兼容 placeholder 效果

    placeholder 是 html5 新增加的属性,主要提供一种提示(hint),用于描述输入域所期待的值.该提示会在输入字段为空时显示,并会在字段获得焦点时消失.placeholder 属性适用于 ...

  2. 跨浏览器实现placeholder效果的jQuery插件

    曾经遇到这样一个问题,处理IE8密码框placeholder属性兼容性.几经周折,这个方案是可以解决问题的. 1.jsp页面引入js插件 <script type="text/java ...

  3. jQuery 两种方法实现IE10以下浏览器的placeholder效果

    /* ** jQuery版本:jQuery-1.8.3.min.js ** 测试的浏览器:IE8,IETester下的IE6-IE9** Author:博客园小dee */ placeholder是H ...

  4. ie兼容placeholder效果

    转载:http://www.jb51.net/article/56244.htm placeholder是HTML5<input>的属性之一,在不同的浏览器( 支持HTML5的现代浏览器 ...

  5. Jquery ajaxSubmit()的浏览器兼容问题

    form.ajaxSubmit({ 2 beforeSubmit: function() { 3 if (FinanceUtil.validate(form)) { 4 FinanceUtil.loa ...

  6. 低版本IE内核浏览器兼容placeholder属性解决办法

    最简便的一个方法,通过js实现. <input type="text" name="username" id="username" v ...

  7. 兼容IE浏览器的placeholder【超不错】

    jQuery EnPlaceholder plug (兼容IE浏览器的placeholder)使用 >>>>>>>>>>>>&g ...

  8. jQuery效果之封装模拟placeholder效果,让低版本浏览器也支持

    页面中的输入框默认的提示文字一般使用placeholder属性就可以了,即: <input type="text" name="username" pla ...

  9. IE下支持文本框和密码框placeholder效果的JQuery插件

    基于jQuery实现的,主要用于IE下实现placeholder效果,可同时支持文本和密码输入框.placeholder是HTML5新增的一个属性,当input设置了该属性后,该值的内容将作为灰色提示 ...

随机推荐

  1. MD5类库(hex_md5)

    /*  * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message  * Digest Algorithm, as ...

  2. java算法 蓝桥杯 文化之旅

    问题描述 有一位使者要游历各国,他每到一个国家,都能学到一种文化,但他不愿意学习任何一种文化超过一次(即如果他学习了某种文化,则他就不能到达其他有这种文化的国家).不同的国家可能有相同的文化.不同文化 ...

  3. go_函数

    函数语法要点 返回值类型写在最后面 可返回多个值 函数可作为参数 没有默认参数,可选参数,只有可变参数列表(...int) package main import ( "fmt" ...

  4. TCP端口状态说明ESTABLISHED、TIME_WAIT、 CLOSE_WAIT

    一. 首先说下tcp端口的几种状态: 1.LISTENING状态 FTP服务启动后首先处于侦听(LISTENING)状态. 2.ESTABLISHED状态 ESTABLISHED的意思是建立连接.表示 ...

  5. K.O. ----- 配置文件没有提示

    ---------------siwuxie095 K.O. ----- 配置文件没有提示 1.解决方法一:联网 只要 PC 联网,配置文件中就有提示 2.解决方法二:手动导入约束文件 约束文件:hi ...

  6. Mule ESB 安装基本配置要求

    Hardware Requirements* 2GHz, dual-core CPU, or 2 virtual CPUs in virtualized environments 2GB of RAM ...

  7. cacti-不出图形,cacti.log中出“ERROR: SQL Assoc Failed!

    [root@CactiEZ log]# tail cacti.log 2016年04月06日 14:53:16 PM - CMDPHP: Poller[0] ERROR: SQL Cell Faile ...

  8. 面向对象的JavaScript-001

    一. Question是父类,MultipleChoiceQuestion和DragDropQuestion是子类 二. 1. <script> // 面向对象 function Ques ...

  9. [c++] final override keyword

    the two keyword are aimed at virtual function final final function must be a virtual funtion , final ...

  10. Asp.net相关知识和经验的碎片化记录

    1.解决IIS7.0下“HTTP 错误 404.15 - Not Found 请求筛选模块被配置为拒绝包含的查询字符串过长的请求”问题 方案1:在程序的web.config中system.web节点里 ...