我试图改变下面的代码,以便如果“this”包含类“search_init”,它将只会替换该类,因为标记本身有多个类应用于它。我尝试过〜=和^ =,但是这给了我关于missing()的错误。jquery更改==包含?
$("tfoot input").focus(function() {
if (this.className == "search_init") {
this.className = "";
this.value = "";
}
});
简短,高效,可读。 +1 – whiskeysierra 2010-02-13 15:32:33
+1,尽管你可以用$(this).filter('。search_init')来缩短它。removeClass('search_init).val('');' – user113716 2010-02-13 17:47:40
@patrick是的,但是你和你在一起可以在空的jQuery对象上运行removeClass和val,这是一种浪费。 – PetersenDidIt 2010-03-11 01:21:48