为什么我不能在“ on”处理程序中将变量写为选择器。怎么会对?
var buttons = $('.sector').find('button');
$(document).on('click', buttons, function() { // here buttons not found
//...
})
$(document).on('click', '.sector button', function() { // here works
//...
})
内容可以在ajax请求之后,所以我需要写$(document)而不是$(buttons)!?
您可以将其绑定到要通过ajax将内容更新到的div父级。
$('#ParentDivOfUpdateId').on('click', '.sector button', function() {
// here ParentDivOfUpdateId is Id of div which is parent to your dynamic content
//...
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句