原文:https://www.oschina.net/code/snippet_206691_26471#44160

让支持的直接路过,不支持的,完美显示~~

/*
 * jQuery placeholder, fix for IE6,7,8,9
 * @author JENA
 * @since 20131115.1504
 * @website ishere.cn
 */
var JPlaceHolder = {
    //检测
    _check : function(){
        return 'placeholder' in document.createElement('input');
    },
    //初始化
    init : function(){
        if(!this._check()){
            this.fix();
        }
    },
    //修复
    fix : function(){
        jQuery(':input[placeholder]').each(function(index, element) {
            var self = $(this), txt = self.attr('placeholder');
            self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
            var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
            var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top, height:h, lienHeight:h, paddingLeft:paddingleft, color:'#aaa'}).appendTo(self.parent());
            self.focusin(function(e) {
                holder.hide();
            }).focusout(function(e) {
                if(!self.val()){
                    holder.show();
                }
            });
            holder.click(function(e) {
                holder.hide();
                self.focus();
            });
        });
    }
};
//执行
jQuery(function(){
    JPlaceHolder.init();   
});
 
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery JPlaceholder Demo</title>
<script src="jquery-1.8.3.min.js"></script>
<script src="jquery.JPlaceholder.js"></script>
</head>
 
<body>
<form>
<div>
  <ul>
    <li>
      <input type="text" name="username" placeholder="用户名">
    </li>
    <li>
      <input type="password" name="username" placeholder="密码">
    </li>
    <li>
      <button type="button">登录</button>
    </li>
  </ul>
</div>
</form>
</body>
</html>

让IE支持placeholder属性~的更多相关文章

  1. 让ie8支持 placeholder 属性

    一.  ie8支持 placeholder 属性 /* * ie8支持 placeholder 属性 */ $(function(){ if( !('placeholder' in document. ...

  2. input date 支持placeholder属性

    第一种解决方法:IE,火狐浏览器,不支持input date的日历功能,火狐支持日历功能   ie,火狐,谷歌显示placeholder属性 css代码 #dateofday:before{  col ...

  3. 在IE8等不支持placeholder属性的浏览器中模拟placeholder效果

    placeholder是一个很有用的属性,可以提示用户在input框中输入正确的内容,但是IE8以及IE8一下的浏览器不支持该属性,我们可以使用js来模拟相似的效果.下面直接上代码: <!doc ...

  4. 让ie支持placeholder属性,一段js搞定

    placeholder属性真的是超级好用的新属性,可惜,只有新版浏览器才支持,为了写出输入框贴心提示,老方法就是加span标签覆盖,营造出placeholder提示的感觉,现在安利一款好用的js,好用 ...

  5. 基于jquery 的插件,让IE支持placeholder属性

    开发一个项目的时候为了美观和用户体验用到了input标签的placeholder属性,但是这个属性是html5中的,所以低版本的IE浏览器不支持.于是在百度找了一些解决方法,找了好几个都不是那么完美, ...

  6. 有关ie9 以下不支持placeholder属性以及获得焦点placeholder的移除

    (一)placeholder 属性起到提示客户输入信息作用 (二)ie9以下出问题了 placeholder不支持 (三)解决办法 先贴html 加上jquery代码就可以了 关于表单获取焦点,chr ...

  7. 让div支持placeholder属性/模拟输入框的placeholder属性

    实现方式:css div:empty:before{ content: attr(placeholder); color:#bbb;}div:focus:before{ content:none; }

  8. IE9以下不支持placeholder属性

    jquery.placeholder.min.js 这个js可以去这个网站搜索https://www.bootcdn.cn/jquery-placeholder/ 使用这个jquery.placeho ...

  9. i8浏览器不支持placeholder属性解决办法,以及解决后,文字不居中问题

    这里想实现的效果是:设置和移除文本框默认值,如下图鼠标放到文本框中的时候,灰字消失. 1.可以用简单的方式,就是给input文本框加上onfocus属性,如下代码: <input id=&quo ...

随机推荐

  1. threadlocal类

    1.threadlocal对象为线程提供变量的副本,该副本为线程私有的,其它线程访问不到: 2.变量的副本存储在ThreadLocalMap对象中: 3.使用threadlocal时候,最好先使用in ...

  2. writel(readl(&pwm_timer->tcfg0) | 0xff, &pwm_timer->tcfg0);

    解析这句代码什么意思! 神说:选定预分频器0 为什么? 神说:因为实验中选的是timer1,在预分频器0下: 若选择timer4,该如何写这句代码? 首先看tcfg0中选择预分频器1,在看tcfg1里 ...

  3. SQL笔记-第三章,数据的增删改

    1.数据的插入 简单的INSERT语句 INSERT INTO T_Person(FName,FAge,FRemark) VALUES(‘Tom’,18,’USA’) 简化的INSERT语句(只对部分 ...

  4. JAVA编程规则【转自java编程思想】

    本附录包含了大量有用的建议,帮助大家进行低级程序设计,并提供了代码编写的一般性指导: (1) 类名首字母应该大写.字段.方法以及对象(句柄)的首字母应小写.对于所有标识符,其中包含的所有单词都应紧靠在 ...

  5. Java利用aspose-words将word文档转换成pdf(破解 无水印)

    首先下载aspose-words-15.8.0-jdk16.jar包 http://pan.baidu.com/s/1nvbJwnv 引入jar包,编写Java代码 package doc; impo ...

  6. 遇到一个奇葩的问题,could not load the assembly file XXX downloaded from the Web

    在我这编译好好滴,发给客户那边居然不通过,报could not load the assembly file:///xxx.dll, 查阅了一些文档后,发现原来是文件的安全问题,是由于我把文件压缩打包 ...

  7. VS2013中,RDLC设置数据源和参数的界面

    今天打开RDLC文件设置参数和数据源时,始终找不到那个窗口,原来那个窗口叫“报表数据”,在“视图”菜单的最下面! 另外:要在当前窗口时打开的RDLC文件时,视图下面才有该选项!!! 参考:http:/ ...

  8. UIImageView、UISlider、UISwitch、UIStepper、UISegmentControl

    UIImageView——图像视图 作用:专门用来显示图片的控件 . 设置图像 [self.imageView setImage:[UIImage imageNamed:@"abc.png& ...

  9. flex 正则 验证

    验证数字:^[-]*$ 验证n位的数字:^\d{n}$ 验证至少n位数字:^\d{n,}$ 验证m-n位的数字:^\d{m,n}$ 验证零和非零开头的数字:^(|[-][-]*)$ 验证有两位小数的正 ...

  10. web storage的用法

    Web Storage分为两种: sessionStorage localStorage 从字面意思就可以很清楚的看出来,sessionStorage将数据保存在session中,浏览器关闭也就没了: ...