Re: [問題] 事件綁定在父節點
想在請問一下
$('#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
11/23 20:48, 1F
討論串 (同標題文章)
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章