//兼容placeholder nodes: 需要兼容的元素,placeholder里面字体的颜色
function placeholder(nodes, itemColor) {
/**
* 判断浏览器是否支持placeholder
* !("placeholder" in document.createElement("input") ----浏览器不支持placeholder属性
*/
if (nodes.length && !("placeholder" in document.createElement("input"))) {
for (var i = 0; i < nodes.length; i++) {//遍历需要添加placeholder的元素
var self = nodes[i],
placeholder = self.getAttribute('placeholder') || '';//获取placeholder属性的值
//绑定onfocus事件(焦点事件:清空placeholder的值和颜色)
self.onfocus = function () {
if (self.value == placeholder) {
self.value = '';
self.style.color = '';
}
}
//绑定onblur事件(赋值和添加颜色)
self.onblur = function () {
if (self.value == "") {
self.value = placeholder;
self.style.color = itemColor;
}
}
//没有点击事件时
self.value = placeholder;//赋值
self.style.color = itemColor;//添加颜色
}
}
}
var item = document.getElementsByTagName('input');
placeholder(item, "red");
分享到:
相关推荐
IE8 placeholder 兼容使用插件。可兼容password类型,可以正常显示提示字。
jQuery placeholder实现源码(兼容所有浏览器)
完美兼容H5 placeholder属性在IE9及以下版本的问题 自测可用,修改点少
处理IE不兼容placeholder的JS文件
使用jQuery快速解决input中placeholder值在ie中无法支持的问题
兼容ie8、ie9的placeholder属性,其他浏览器用自身的placeholder。在ie8和ie9浏览器,点击span则让input聚焦。
这是一个关于兼容input下placeholder的属性的方法,通过js来用另外一中方法来实现
用span标签定位到placeholder位置,用jq控制span的显示和隐藏。
ie6 7 8兼容html5属性placeholder
该插件完整兼容placeholder属性。插件由原生JS编写,无需任何其他插件支持,并且使用简单,只需一行JS调用即可。 博客地址:http://blog.csdn.net/qq_17076445/article/details/78212240
使用该插件(jquery.placeholder.js)解决IE9及以版本下对placeholder的兼容性问题
全局设置placeholder.attr :指定占位符特性名称,默认为数据占位符placeholder.color :指定占位符的文字前景色,默认为#888 用法: <html> <head></head> <body> <form> <input...
具体看博客说明 https://blog.csdn.net/u011611479/article/details/112851238
复制代码代码如下: //placeholder功能实现 var placeholder = { add: function (el) { if (!(‘placeholder’ in document.createElement(‘input’))) { var self = placeholder; el.each(functio
现在流行html5了都,所有的浏览器都支持placeholder,唯独IE不支持,那么这插件将完美解决IE浏览器不兼容input标签的placeholder属性.
nd-placeholder兼容浏览器的placehodler##弃用原先的使用的安装$ spm install nd-placeholder --save使用var Placeholder = require('nd-placeholder');// use Placeholder
IE8兼容提示语 !
placeHolder是html5加入的新属性,此代码基于jQuery实现placeholder属性功能。
这里面是一个支持IE9以及IE9一下的兼容支持placeholder的javascript案例。本示例是争对textarea写的,修改后可以争对input。另外textarea只需要添加一个name="textarea" 即可实现。需要实现input支持的,需要修改三...