<!-- 对于IE 10 以下版本placeholder的兼容性调整 -->
<!--[if lt IE 10]>
<script>
$(function(){
$("input[type!='password'],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);
}
}
});
$("input[type!='password'],textarea").each(function(i,n){
$(this).val($(this).attr("placeholder"));
});
$("input[type='password']").bind({
"focus":function(){
var placeholderVal = $(this).attr("placeholder");
var realVal = $(this).val();
if($.trim(realVal)==placeholderVal){
var copy_this = $(this).clone(true,true);
$(copy_this).attr("type","password");
$(copy_this).insertAfter($(this));
$(this).remove();
$(copy_this).val("");
$(copy_this).focus();
}
},
"blur":function(){
var placeholderVal = $(this).attr("placeholder");
var realVal = $(this).val();
if($.trim(realVal)==""){
var copy_this = $(this).clone(true,true);
$(copy_this).attr("type","text");
$(copy_this).insertAfter($(this));
$(this).remove();
$(copy_this).val(placeholderVal);
}
}
});
$("input[type='password']").each(function(i,n){
var placeHolderVal = $(this).attr("placeholder");
var copy_this = $(this).clone(true,true);
$(copy_this).attr("type","text");
$(copy_this).insertAfter($(this));
$(this).remove();
$(copy_this).val(placeHolderVal);
});
});
</script>
<![endif]-->
继续更新,
<input type="password" id="loginPassword" placeholder="密码(6-16位字母数字)" class="width270">
<input type="text" passwordMask="true" placeholder="密码(6-16位字母数字)" style="display:none;" class="width270">
<!-- 对于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]-->