让IE下支持Html5的placeholder属性
HTML5对Web Form做了许多增强,比如input新增的type类型、Form Validation等。
Placeholder
是HTML5新增的另一个属性,当input或者textarea设置了该属性后,该值的内容将作为灰字提示显示在文本框中,当文本框获得焦点时,提示文
字消失。以前要实现这效果都是用JavaScript来控制才能实现 , firefox、google chrome等表示对其支持 ,
唯独IE存在违和感啊!
例如: <input id="t1" type="text" placeholder="请输入文字" />
介绍一个超强的让IE下支持placeholder的属性插件,同时也兼容其他不支持placeholder的浏览器,代码如下:
代码如下:
$(document).ready(function(){
var doc=document,
inputs=doc.getElementsByTagName('input'),
supportPlaceholder='placeholder'in doc.createElement('input'),
placeholder=function(input){
var text=input.getAttribute('placeholder'),
defaultValue=input.defaultValue;
if(defaultValue==''){
input.value=text
}
input.onfocus=function(){
if(input.value===text)
{
this.value=''
}
};
input.onblur=function(){
if(input.value===''){
this.value=text
}
}
};
if(!supportPlaceholder){
for(var i=0,len=inputs.length;i<len;i++){
var input=inputs[i],
text=input.getAttribute('placeholder');
if(input.type==='text'&&text){
placeholder(input)
}
}
}
});
直接把代码复制下来,保存成一个js文件引用即可,不用再做任何处理,超级便利!
ex
:
这样做的确能让IE的Input显示placeholder属性,但是如果页面上只有一个input还好,如果是多个input,如果出现input没有
填入任何值的话,那么它的空input会自动将placeholder的值填进value里面,从而发生错误.例如:
代码如下:
<input type="text" placeholder="输入商品编码" name="goodscode" id="goodscode" value="123" />
<input type="text" placeholder="输入商品名称" name="goodsname" id="goodsname" value="输入商品名称" />
解决办法就是在后台自己判断啦 , 也许能在上面的js文件里解决 , 以后再研究啦~!
让IE下支持Html5的placeholder属性的更多相关文章
- input 不支持HTML5的placeholder属性
解决方法如下: <input type="text" value="搜索乐高资讯" onfocus="if(this.value=='搜索乐高资 ...
- HTML5之placeholder属性以及如何更改placeholder属性中文字颜色
今天在群里看到群友问了一个这样的问题,就是如何更改placeholder属性中文字的颜色,以前用过这属性,却是没更改过颜色,于是便试了试,中途遇到些问题,查找资料后特来总结一下. 熟悉HTML5的人应 ...
- 转: HTML5之placeholder属性以及如何更改placeholder属性中文字颜色
今天在群里看到群友问了一个这样的问题,就是如何更改placeholder属性中文字的颜色,以前用过这属性,却是没更改过颜色,于是便试了试,中途遇到些问题,查找资料后特来总结一下. 熟悉HTML5的人应 ...
- html5的placeholder属性(IE如何兼容placeholder属性)
界面UI推荐 jquery html5 实现placeholder兼容password IE6 html5的placeholder属性(IE如何兼容placeholder属性) 2013-01-05 ...
- 【工作笔记五】html5的placeholder属性(IE如何兼容placeholder属性)
placeholder属性,IE对其的支持表示无奈,firefox.google chrome表示毫无压力. HTML5对Web Form做了许多增强,比如input新增的type类型.Form Va ...
- Html5 input placeholder 属性字体颜色修改。
这篇文章主要介绍了有关HTML5 input placeholder 颜色修改方面的知识,需要的朋友可以参考下 Chrome支持input=[type=text]占位文本属性,但下列CSS样式 ...
- Html5的placeholder属性(IE兼容)
HTML5对Web Form做了很多增强,比方input新增的type类型.Form Validation等. Placeholder是HTML5新增的还有一个属性,当input或者textarea设 ...
- IE低版本下实现html5的placeholder(表单提示)功能
placeholder 属性提供可描述输入字段预期值的提示信息(hint). 该提示会在输入字段为空时显示,并会在字段获得焦点时消失. 注释:placeholder 属性适用于以下的 <inpu ...
- IE不支持HTML5表单属性placeholder的解决办法
1. [代码][JavaScript]代码 (function ($) { $.fn.placeholder = function (options) { var defaults ...
随机推荐
- ListBox1控件
前台: <div> <asp:ListBox ID="ListBox1" runat="server" AutoPostBack=" ...
- 28. 字符串的全排列之第2篇[string permutation with repeating chars]
[本文链接] http://www.cnblogs.com/hellogiser/p/string-permutation-with-repeating-chars.html [题目] 输入一个字符串 ...
- HDU2018递推牛
母牛的故事 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- [MAC] SVN lock的使用
转载 : http://www.eefocus.com/czzheng/blog/12-03/245532_4ca94.html 如果压根没有锁lock,那么每个人都拥有一个本地copy,每个人都能自 ...
- July 14th, Week 29th Thursday, 2016
Risk comes from not knowing what you are doing. 风险常常来自于不知道自己在做什么. What is risk? I think risk means t ...
- HTTP状态码整理
状态消息 1xx:信息 消息 描述 100 Continue 服务器仅接收到部分请求,但是一旦服务器并没有拒绝该请求,客户端应该继续发送其余的请求. 101 Switching Protocols 服 ...
- JqueryEasyUI教程
第一章EasyUI中弹出框dialog的使用为div标签加上class="easyui-dialog"即可使用一.引入文件介绍jquery.min.js:jquery核心文件,不再 ...
- Android之Bundle类
API文档说明 1.介绍 用于不同Activity之间的数据传递 1.重要方法 clear():清除此Bundle映射中的所有保存的数据. clone():克隆当前Bundle containsKey ...
- 无线ap和路由器wifi热点怎么区分和区别
转自:http://blog.sina.com.cn/s/blog_5a6efa330101yrzh.html 有的人发现无线ap和无线路由器都可以实现无线上网,于是到无线市场买了个相当便宜的无线ap ...
- Redis中常用命令
连接操作相关的命令 quit:关闭连接(connection) auth:简单密码认证 持久化 save:将数据同步保存到磁盘 bgsave:将数据异步保存到磁盘 lastsave:返回上次成功将数据 ...