jQuery实现ie浏览器兼容placeholder效果
<!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效果的更多相关文章
- 【jquery】基于 jquery 实现 ie 浏览器兼容 placeholder 效果
placeholder 是 html5 新增加的属性,主要提供一种提示(hint),用于描述输入域所期待的值.该提示会在输入字段为空时显示,并会在字段获得焦点时消失.placeholder 属性适用于 ...
- 跨浏览器实现placeholder效果的jQuery插件
曾经遇到这样一个问题,处理IE8密码框placeholder属性兼容性.几经周折,这个方案是可以解决问题的. 1.jsp页面引入js插件 <script type="text/java ...
- jQuery 两种方法实现IE10以下浏览器的placeholder效果
/* ** jQuery版本:jQuery-1.8.3.min.js ** 测试的浏览器:IE8,IETester下的IE6-IE9** Author:博客园小dee */ placeholder是H ...
- ie兼容placeholder效果
转载:http://www.jb51.net/article/56244.htm placeholder是HTML5<input>的属性之一,在不同的浏览器( 支持HTML5的现代浏览器 ...
- Jquery ajaxSubmit()的浏览器兼容问题
form.ajaxSubmit({ 2 beforeSubmit: function() { 3 if (FinanceUtil.validate(form)) { 4 FinanceUtil.loa ...
- 低版本IE内核浏览器兼容placeholder属性解决办法
最简便的一个方法,通过js实现. <input type="text" name="username" id="username" v ...
- 兼容IE浏览器的placeholder【超不错】
jQuery EnPlaceholder plug (兼容IE浏览器的placeholder)使用 >>>>>>>>>>>>&g ...
- jQuery效果之封装模拟placeholder效果,让低版本浏览器也支持
页面中的输入框默认的提示文字一般使用placeholder属性就可以了,即: <input type="text" name="username" pla ...
- IE下支持文本框和密码框placeholder效果的JQuery插件
基于jQuery实现的,主要用于IE下实现placeholder效果,可同时支持文本和密码输入框.placeholder是HTML5新增的一个属性,当input设置了该属性后,该值的内容将作为灰色提示 ...
随机推荐
- MySQL篇之Navicat可视化工具
主要内容: Navicat工具的介绍和使用 1.介绍和下载安装 <1>介绍 Navicat是一款针对MySQL数据库开发的可视化管理工具,以图形界面的形式操作MySQL数据库. 但在生产环 ...
- Creating Cubemaps in Unity3D
[Creating Cubemaps in Unity3D] 1.在Editor目录下生成GenerateStaticCubemap.cs. 2.编写代码,生成一个继承于ScriptableWizar ...
- tensorflow学习笔记----tensorflow在windows的安装及TensorBoard中mnist样例
前言: ...
- [C++] Returning values by reference in C++
A C++ program can be made easier to read and maintain by using references rather than pointers. A C+ ...
- [C++] any number to binary (Bit manipulation)
any number to binary (Bit manipulation)
- ant+proguard签名打包 .jar
ant+proguard签名打包 .jar 摘自: https://blog.csdn.net/a_ycmbc/article/details/53432812 2016年12月02日 14:52:3 ...
- BCompare 4重置试用天数
BCompare安装后有30天试用期,试用结束后,你可以卸载重装,以重新获得30天试用天数. BCompare的使用天数记录保存在注册表中,如果不想每次重装,也可删除对应的注册表值来重置激活天数. 命 ...
- Android Touch 事件总结
---恢复内容开始--- 1.Touch事件传递机制 过程有点儿类似于栈, ViewGroup的子类有都继承它的以下3个方法: public boolean dispatchTouchEvent(Mo ...
- [GO]ticker的使用
package main import ( "time" "fmt" ) //ticker是一个定时触发的计时器,它会以一个间隔往channel发送整一个事件( ...
- 42 :809*x=800*x+9*x+1
题目:809*x=800*x+9*x+1(去掉最后的1有解)其中x代表的两位数,8*x的结果为两位数,9*x的结果为3位数.求x代表的两位数,及809*x后的结果(两种方法实现) public cla ...