直接上代码:

   $(document).ready(function () {
var doc = document,
textareas = doc.getElementsByTagName('textarea'),
supportPlaceholder = 'placeholder' in doc.createElement('textarea'), placeholder = function (textarea) {
var text = textarea.getAttribute('placeholder'),
defaultValue = textarea.defaultValue;
if (defaultValue == '') {
textarea.value = text
}
textarea.onfocus = function () {
if (textarea.value === text) {
this.value = ''
}
};
textarea.onblur = function () {
if (textarea.value === '') {
this.value = text
}
}
}; if (!supportPlaceholder) {
for (var i = 0, len = textareas.length; i < len; i++) {
var textarea = textareas[i],
text = textarea.getAttribute('placeholder');
if ( text) {
placeholder(textarea);
}
}
}
});

textarea可以换成input

【JS】IE兼容placeholder的更多相关文章

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

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

  2. jQuery实现ie浏览器兼容placeholder效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 兼容placeholder

    众所周知.IE9以下不兼容placeholder属性,因此自己定义了一个jQuery插件placeHolder.js.以下为placeHolder.js的代码: /** * 该控件兼容IE9下面,专门 ...

  4. html5的placeholder属性(IE如何兼容placeholder属性)

    界面UI推荐 jquery html5 实现placeholder兼容password  IE6 html5的placeholder属性(IE如何兼容placeholder属性) 2013-01-05 ...

  5. 设为首页 和 收藏本站js代码 兼容IE,chrome,ff

    设为首页 和 收藏本站js代码 兼容IE,chrome,ff //设为首页 function SetHome(obj,url){ try{ obj.style.behavior='url(#defau ...

  6. 关于js的兼容问题(小办法)!

    今天整理了一下浏览器对JS的兼容问题,希望能给你们带来帮助,我没想到的地方请留言给我,我再加上: 常遇到的关于浏览器的宽高问题: //以下均可console.log()实验 var winW=docu ...

  7. js基础 - 兼容代码

    js基础 - 兼容代码 . scrollTop . chrome document.body.scrollTop . IE && firefox document.documentEl ...

  8. 图片旋转+剪裁js插件(兼容各浏览器) « 张鑫旭-鑫空间-鑫生活

    图片旋转+剪裁js插件(兼容各浏览器) « 张鑫旭-鑫空间-鑫生活 图片旋转+剪裁js插件(兼容各浏览器) by zhangxinxu from http://www.zhangxinxu.com 本 ...

  9. JS播放声音 兼容所有浏览器

    JS播放声音 兼容所有浏览器 <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http ...

  10. js操作css样式、js的兼容问题

    一.js操作css样式 div . style . width="200px" 在div标签内我们添加了一个style属性,并设定width值.这种写法会给标签带来大量的style ...

随机推荐

  1. JavaEE 概念

    JavaEE体系架构概述 1.  企业级应用 现代企业级应用是以服务器为中心,通过网络把服务器和分散的用户联系在一起的应用.一般来说,现代企业级应用应当具有如下需求: 并发支持:同时收到大量服务请求, ...

  2. VC环境配置办法

    在VS工程中,添加c/c++工程中外部头文件及库的基本步骤:1.添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录:加上头文件存放目录.2.添加文件引用的l ...

  3. 【 2013 Multi-University Training Contest 3 】

    HDU 4622 Reincarnation 枚举字符串的起点,构造后缀自动机,每次插入一个字符,就能统计得到当前不同字串的个数,预处理出所有的询问. #include<cstdio> # ...

  4. 转-squid介绍及其简单配置

    本文原始出处:http://linuxme.blog.51cto.com/1850814/372960 1.Squid是什么? Squid中文权威指南:http://zyan.cc/book/squi ...

  5. C++ 类模板的使用

    从事C++挺久了,在前段时看书时,发现高手,都是在写模板无,泛型编程,顿感差距.自己连模板都没有写,于是就小小的研究了下模板的用法. 模板简而言之就是对某此对象的相同方法,或处理方式,进行归纳,总结, ...

  6. python导入cx_Oracle报错的问题!

    import cx_Oracle 总是报错:ImportError: DLL load failed: 找不到指定的模块. 或者:ImportError: DLL load failed: %1 不是 ...

  7. php __invoke 和 __autoload

    当在对象后面添加()时候调用 __invoke <?php class Person { private $name; private $age; public function __const ...

  8. sql inner join , left join, right join , union,union all 的用法和区别

    Persons 表: Id_P LastName FirstName Address City 1 Adams John Oxford Street London 2 Bush George Fift ...

  9. z变换

    ---恢复内容开始--- z变换作用很大 将离散信号从时间域转到频率域 网址 ---恢复内容结束--- z变换作用很大 将离散信号从时间域转到频率域 网址 http://stackoverflow.c ...

  10. IELTS - Word List 28

    1, The lawsuit is very much o the lawyer's mind. 2, The canteen was absolutely packed. 3, Doctors di ...