placeholder不兼容 IE10 以下版本的解决方法
对于密码输入框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>
最新文章
- Redis_redis分布式锁-SETNX
- C#设计模式系列:简单工厂模式(Simple Factory)
- eclipse的常用快捷键
- 建造者模式与原型模式/builder模式与prototype模式/创建型模式
- &#39;NSUnknownKeyException&#39; this class is not key value coding-compliant for the key XXX
- rnqoj-82-又上锁妖塔-dp
- Android Studio导入Eclipse项目
- 一个高级PHP工程师所应该具备的
- Oracle trunc函数
- iOS开展UI一片—简单的浏览器观看节目
- iOS 类库列表
- 1、阿里云ECS内部机器端口被100.117.90段的ip疯狂扫描导致业务异常
- OC 中property的使用
- windows部分常用命令
- 01-Python的基础知识3
- SQL Server CLR 使用 C# 自定义函数
- RAC配置(启停库)
- Android笔记——Activity中的回传数据案例(装备选择)
- Address already in use
- binlog之三:binlog开启、查看