weixin_33691598 2014-09-22 03:30 采纳率: 0%
浏览 171

jQuery的用法:$(document).on()[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/16057640/difference-between-on-functions-calls" dir="ltr">Difference between .on() functions calls</a>
                            <span class="question-originals-answer-count">
                                (3 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2014-09-22 04:11:15Z" class="relativetime">5 years ago</span>.</div>
        </div>
    </aside>

I want to use jquery .on() to do the AJAX

Anyway,I test two method below,both of them works
I want to know what's the difference between them??
are the both method correct?

<script type="text/javascript">
/*method 1*/
/*$(document).on('submit', '.login-form', function(){ */
$(document).on('click', '.searchtitle', function(){
    ttest = $(this).serialize();
    console.log(ttest);    
});
/*method 2*/
$(".searchtitle").on('click',   function(){
    ttest = $(this).serialize();
    console.log(ttest);    
});
</script>

test.html
<form action="" method="post"  class="searchtitle">
    {% csrf_token %}
    search activity :<input type="text" name="title">
    <button type="button" class="btn .btn-sm btn-success" id="search">submit</button>
</form>
</div>
  • 写回答

3条回答 默认 最新

  • weixin_33747129 2014-09-22 03:33
    关注

    Method two is better for performance reason since you limit the scope of the checking that needs to happen every time there is a button click.

    The first approach is no more performant than the now deprecated live delegate, but necessary if you can't narrow the scope of the region that needs to be monitored for click events.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题