我目前正在努力使用 jQuery 函数,该函数将文本框的标题添加为默认文本,直到用户单击它。我只想要一个特定的文本框来应用这个功能,所以我用'title="Search"'对其进行了修改,以确保它只对标题搜索的字段起作用。但是,这似乎破坏了功能。有谁知道下面的功能有什么问题?
$('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');
        }
    });
});