0

我正在使用一个名为 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(); }
});

编辑: 我已经兑现了 $('this'); 作为建议的对象。

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

4

1 回答 1

0

第一:$(this)应该被缓存。其余的$()也可以被缓存,并且在函数之前。

二:使用策略模式

于 2013-10-09T20:25:52.010 回答