Jquery 函数挂起



我正在使用一个名为h5validate的插件。我发现启动此插件的唯一方法是单击(模糊(我要验证的字段,所以我的逻辑是设置一个函数,当我单击(碰巧(下一个按钮时,它会为我执行此操作;我尝试直接调用验证函数,但它不起作用。

无论如何,我的问题是:

1.此功能会挂起浏览器~3秒,为什么?

$(document).on('click', '.tab', function () {
$this = $(this);
    if( $this.is('#tab1') )     { $('.tab-content-first .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab2') )     { $('.tab-content-1 .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab3') )     { $('.tab-content-2 .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab4') )     { $('.tab-content-3 .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab5') )     { $('.tab-content-4 .row .cell input:not(#ImageLocation)').blur(); }
    if( $this.is('#tab6') )     { $('.tab-content-5 .row .cell input:not(#ImageLocation)').blur(); }
});

编辑:我已经兑现了 $("这个"(;作为建议的对象。

我已经决定它可能正在冒泡,文档建议我停止传播((,但这不起作用,我正在使用委派,因为我通过 ajax 调用它,这就是 stoppropagation(( 不起作用的原因吗?

第一:$(this)应该被缓存。$()其余部分也可以在函数之前缓存。

第二:使用策略模式

最新更新