<script type=
"text/javascript"
>
if
( !(
'placeholder'
in
document.createElement(
'input'
)) ){
$(
'input[placeholder],textarea[placeholder]'
).each(
function
(){
var
that = $(
this
),
text= that.attr(
'placeholder'
);
if
(that.val()===
""
){
that.val(text).addClass(
'placeholder'
);
}
that.focus(
function
(){
if
(that.val()===text){
that.val(
""
).removeClass(
'placeholder'
);
}
})
.blur(
function
(){
if
(that.val()===
""
){
that.val(text).addClass(
'placeholder'
);
}
})
.closest(
'form'
).submit(
function
(){
if
(that.val() === text){
that.val(
''
);
}
});
});
}
</script>
这个方法只可以解决表单提交的问题,但如果是取值的话,还是不能支持。
解决方法是在input框里再下一个层放一个label
<label class="placeholder" for="username_1" style="display: block;">邮箱或手机号</label>
如果有值就不显示这个label,无值就显示这个label