placeholder
打开一个那边发过来的页面,里面全是placeholder。没见过,一时气愤全部ko,用传统的方法都能搞定的东西,为啥要标新立异!
后来发现如果想在input password里显示个把汉字,还真是不容易,总不能让我加个absolute的label吧。于是乎又想起了之前的placeholder,在手机端的页面,还是蛮支持的,拿来用用,也好。。。
解决问题:
input的占位符,不必再自己写提示文字以及focus blur的判定语句
效果:

代码:
//检测是否支持place-holder
function placeHolderSupport(){
return "placeholder" in document.createElement("input");
}
if(!placeHolderSupport()){
$(document.body).addClass("unsupport_placeholder");
$(".input-item").focus(function(){
$(this).parent().find("label").hide();
}).blur(function(){
var el = $(this),
val = el.val();
console.log("dd",val);
if(val.length == 0){
el.parent().find("label").show();
}
})
}
<input placeholder="密码:" class="input-item" type="password" id="password" name="password" value="" required />
浙公网安备 33010602011771号