Re: [問題] 事件綁定在父節點

看板Ajax作者 (米沙)時間15年前 (2010/11/23 11:44), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串4/5 (看更多)
想在請問一下 $('#parent_p').bind('click',function(evt){ var o=evt.target; alert( $(o).attr('id') ) }) $('#parent_p a', $('#parent_p') ).bind('click',function(){ alert( $(this).attr('id') ) }) 兩者是不是 效能差不多?? ※ 引述《mesak (米沙)》之銘言: : 請問有沒有辦法 用 JQUERY 把事件綁在父節點 : 例如 : <div id="parent_p"> : <a href="#" id="a1">aaa</a> : <a href="#" id="a2">aaa</a> : </div> : $('#parent_p').click(function(){ : alert(???) //點到哪一個 a 就取得 id : }) : 因為 會變動 html 不想綁 LIVE.... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 112.105.244.163

11/23 20:48, , 1F
如果這樣綁在 a上,每個 a都要宣告自己的暱名函數
11/23 20:48, 1F
文章代碼(AID): #1CwpYKQ3 (Ajax)
討論串 (同標題文章)
文章代碼(AID): #1CwpYKQ3 (Ajax)