对于密码输入框placeholder的兼容问题:

HTML代码:

<input type="password" id="loginPassword" placeholder="密码(6-16位字母数字)" class="width270">
<input type="text" passwordMask="true" placeholder="密码(6-16位字母数字)" style="display:none;"

class="width270">

JS代码:
<!-- 对于IE 10 以下版本placeholder的兼容性调整 -->

<!--[if lt IE 10]>

<script>

$(function(){

//文本域的事件监听

$("input[type!='password'][passwordMask!='true'],textarea").bind({

"focus":function(){

var placeholderVal = $(this).attr("placeholder");

var realVal = $(this).val();

if($.trim(realVal)==placeholderVal){

$(this).val("");

}

},

"blur":function(){

var placeholderVal = $(this).attr("placeholder");

var realVal = $(this).val();

if($.trim(realVal)==""){

$(this).val(placeholderVal);

}

}

});

//初始化除password框之外的文本域

$("input[type!='password'],textarea").each(function(i,n){

$(this).val($(this).attr("placeholder"));

});

//密码框失去焦点,显示文本框

$("input[type='password']").blur(function(){

var next = $(this).next("input[type='text'][passwordMask='true']");
var val = $(this).val();
if($.trim(val)==""){
$(next).show();
$(this).hide();
}
});

//文本框获得焦点,显示密码框
$("input[type='text'][passwordMask='true']").focus(function(){
var prev = $(this).prev("input[type='password']");
$(this).hide();
$(prev).show().focus();
});

//页面初始化密码框为文本框
$("input[type='text'][passwordMask='true']").each(function(i,n){
var prev = $(this).prev("input[type='password']");
$(prev).hide();
$(this).show();
});

});
</script>
<![endif]-->

上面的方法只能解决密码输入框,建议在网上找jQuery的placeholder插件,

有一款jQuery的placeholder插件确实很不多,用起来也挺方便

下载源码地址:https://github.com/jamesallardice/Placeholders.js/

引用方法直接在页面上加载下载好的插件,再调用插件:

<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="js/placeholders.js"></script>

<script type="text/javascript">
    $(function(){ $('input, textarea').placeholder(); });
</script>

最新文章

  1. Redis_redis分布式锁-SETNX
  2. C#设计模式系列:简单工厂模式(Simple Factory)
  3. eclipse的常用快捷键
  4. 建造者模式与原型模式/builder模式与prototype模式/创建型模式
  5. &#39;NSUnknownKeyException&#39; this class is not key value coding-compliant for the key XXX
  6. rnqoj-82-又上锁妖塔-dp
  7. Android Studio导入Eclipse项目
  8. 一个高级PHP工程师所应该具备的
  9. Oracle trunc函数
  10. iOS开展UI一片—简单的浏览器观看节目
  11. iOS 类库列表
  12. 1、阿里云ECS内部机器端口被100.117.90段的ip疯狂扫描导致业务异常
  13. OC 中property的使用
  14. windows部分常用命令
  15. 01-Python的基础知识3
  16. SQL Server CLR 使用 C# 自定义函数
  17. RAC配置(启停库)
  18. Android笔记——Activity中的回传数据案例(装备选择)
  19. Address already in use
  20. binlog之三:binlog开启、查看

热门文章

  1. jsp登入oracle
  2. FreeBSD_11-系统管理——{Part_7 - AUDIT}
  3. 应用Web.Config配置网站
  4. Redis在windows环境下ThinkPHP的安装和使用
  5. [C#]想说一说嵌套数组
  6. jquery 拖拽,框选的一点积累
  7. MVVM框架下 WPF隐藏DataGrid一列
  8. 应用程序框架实战三十八:项目示例VS解决方案的创建(一)
  9. AOP的实现机制--转
  10. table-cell实现宽度自适应布局