我目前正在努力使用jQuery函数,该函数将文本框的标题添加为默认文本,直到用户点击它为止.我只想要一个特定的文本框来应用这个功能,所以我用'title ="搜索"'来修改它,以确保它只在标题搜索的字段上实现.但是,这似乎打破了功能.有谁知道下面的功能有什么问题?
$('input[type="text" title="Search"]').each(function() {
this.value = $(this).attr('title');
$(this).addClass('text-label');
$(this).focus(function() {
if (this.value == $(this).attr('title')) {
this.value = '';
$(this).removeClass('text-label');
}
});
$(this).blur(function() {
if (this.value == '') {
this.value = $(this).attr('title');
$(this).addClass('text-label');
}
});
});
Run Code Online (Sandbox Code Playgroud)