on事件綁定阻止冒泡的問題

來源:互聯網
上載者:User

標籤:事件綁定   add   top   cli   冒泡   doc   gif   com   排隊   

當使用on進行事件綁定時當要給document綁定click,而子項目要禁止冒泡,那麼子項目裡面的子項目的click事件就會無效了,

下面無效版:

$(‘#queue‘).on(‘click‘, ‘.link‘, function() {        var t = $(this)        ,box = t.next()        if(t.hasClass(‘active‘)) {            box.hide()            t.removeClass(‘active‘)        }        else {            box.show()            t.addClass(‘active‘)        }        event.stopPropagation()    })//排隊列表收縮    $(document).on(‘click‘,‘body‘,function(){        $(‘.link‘).removeClass(‘active‘)        $(‘.queue-box‘).hide();    })    $(‘#queue‘).on(‘click‘,‘.queue-box‘,function(){//綁 $(‘#queue‘)或 $(document)都一樣        event.stopPropagation()//主要是下面            $(document).on(‘click‘,‘.btn-queue-join‘,function(){                mywebsocket.send(JSON.stringify({                    "action": "patientJoinQueue",                    "patientCode": patientCode,                    "orderCode": $(this).parents(‘.item‘).attr(‘data-id‘)                }))            });
//修改$(document)為$(‘.queue-box‘)就可以了            $(‘.queue-box‘).on(‘click‘,‘.btn-queue-join‘,function(){                mywebsocket.send(JSON.stringify({                    "action": "patientJoinQueue",                    "patientCode": patientCode,                    "orderCode": $(this).parents(‘.item‘).attr(‘data-id‘)                }))            });

 

 


 

參考http://www.cnblogs.com/tengj/p/4794947.html對其進行了理解

暫時沒空後面補理解

on事件綁定阻止冒泡的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.