本文实例讲述了jquery控制表单输入框显示默认值的方法。分享给大家供大家参考。具体实现方法如下:
$(document).ready(function() {
$('.someClass').each(function() {
var $this = $(this);
var defaultVal = $this.attr('title');
$this.focus(function() {
if ($this.val() === defaultVal) {
$this.val('');
}
});
$this.blur(function() {
if ($this.val().length === 0) {
$this.val(defaultVal);
}
});
});
});
input {
display:block;
margin-bottom:5px;
}
value="Email Address" />
value="Insert form refill here" />
希望本文所述对大家的jQuery程序设计有所帮助。