【前言】
在实践过程中发现jquery.placeholder.js对placeholder支持的效果不是特别理想,placeholder属性值时而会消失,所以建议采用原生JS方案。
【代码】
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>demo测试</title> <style type="text/css"> *{margin: 0;padding: 0} </style> </head> <body> <input type="text" name="username" placeholder="请输入名字"> <script type="text/javascript"> placeholder(); function placeholder() { var doc=document, inputs=doc.getElementsByTagName('input'), //浏览器input域是否支持placeholder 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) } } } } </script> </body> </html>
相关推荐
解决IE下不支持placeholder属性
jquery插件解决IE6到IE9版本不支持placeholder的问题,支持同一个网页包含多个password input的版本。用法:下载插件并引用,将插件代码里面的login-input改成自己的密码input输入框的样式即可。
现在流行html5了都,所有的浏览器都支持placeholder,唯独IE不支持,那么这插件将完美解决IE浏览器不兼容input标签的placeholder属性.
placeHolder是html5加入的新属性,此代码基于jQuery实现placeholder属性功能。
使用jQuery快速解决input中placeholder值在ie中无法支持的问题
简洁的placeholder插件,支持ie9、ie8及以下版本。完美解决ie9中onpropertychange问题。使用简单,引入placeholder.js即可让您的ie完美支持placeholder
但是在不支持html5的低版本的浏览器中,placeholder属性是无效的,为了解决这个问题,因此,人为的去实现placeholder属性: 复制代码代码如下: //placeholder功能实现 var placeholder = { add: function (el) { if...
本篇文章主要介绍了使用jQuery快速解决input中placeholder值在ie中无法支持的问题。需要的朋友可以过来参考下,希望对大家有所帮助
简洁的placeholder插件,支持ie9、ie8及以下版本。完美解决ie9中onpropertychange问题。使用简单,引入placeholder.js即可让您的ie完美支持placeholder
这次使用了bootstrap3,在chrome,firefox,safari,opera,360浏览器(极速模式)、搜狗浏览器等浏览器下均没有问题,而在IE8及IE11下发现样式无法显示,然后各种百度啊,最后在一个网友帖子的帮助下解决了问题,先将...
谷歌、火狐及-webkit-内核的浏览器均支持该属性(css3),IE不支持该属性,所以在IE中,会自动降级,表格无固定列,可滑动的形式。 Edge浏览器在1703之后的版本使用了chromium内核,对css3的属性支持较好,也支持...
1333 解决ie8下面页面抖动的问题 1334 框架错误处理函数处理没有error_get_last的情况 1337 bug创建的时候增加优先级字段 1338 批量创建bug的时候隐藏不需要的bug类型 1339 修复bug操作系统的错误 1340 检查开源...
25、解决后台文章管理模块→左边栏→类目浏览,如果文章类目过多会被遮盖,且无法向下滚动的问题 二、下载 下载地址:http://www.chanzhi.org/download/83_chanzhi2.5.1.html 源码包: ...
蝉知门户系统(changezhiEPS)是一款开源免费的企业门户系统,专为企业营销设计!它内置了文章、产品、论坛、评论、...25、解决后台文章管理模块→左边栏→类目浏览,如果文章类目过多会被遮盖,且无法向下滚动的问题
11、搜索功能会遇到的问题及其解决方案 14 12、搜索过滤 16 13、注意 16 14、WCM高级搜索参数 16 ADVANCED WCM/WEBSPHERE PORTAL SEARCH INTEGRATION 17 Introduction 17 How to search WCM content using this ...