如果.parent().hasclass则不应用该函数

mcm*_*hfy 4 css jquery dom

我有这个函数,只有在父类没有类时才应该调用它cooling.

function inputWidth() {
        $('input[disabled="disabled"]').removeAttr("disabled").prop("readonly", true);
        $('input[type!="submit"]').focus(function(){
            if ($(this).val().length > 20) {
                $(this).attr('data-default', $(this).width());
                $(this).animate({
                    width: 350
                }, 'slow');
                $(this).parent().addClass('cooling');
            }
        }).blur(function(){ /* lookup the original width */
            var w = $(this).attr('data-default');
            $(this).animate({
                width: w
            }, 'fast');
            $(this).parent().removeClass('cooling');
        });
   };
Run Code Online (Sandbox Code Playgroud)

xbo*_*nez 10

if (!$(this).parent().hasClass('cooling'))
{
    //your function
}
Run Code Online (Sandbox Code Playgroud)