jquery更改==包含?

php*_*00b 1 jquery class contains

我正在尝试更改下面的代码,以便如果"this"包含类"search_init",它将只替换该类,因为标记本身有多个类应用于它.我试过〜=和^ =,但这给了我关于missing()的错误.

$("tfoot input").focus( function () {
            if ( this.className == "search_init" )  {
                this.className = "";
                this.value = "";
            }
        } );
Run Code Online (Sandbox Code Playgroud)

Pet*_*dIt 5

试试这个:

$("tfoot input").focus( function () {
    var $this = $(this);
    if ( $this.hasClass("search_init") )  {
        $this.removeClass("search_int").val('');
    }
});
Run Code Online (Sandbox Code Playgroud)