且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用load()函数加载页面后,on('click')jquery无法正常工作

更新时间:2021-12-02 08:46:08

使用事件委托通过 .on()

$(document).on('click','.register-btn',function(){

代替

$('.register-btn').on('click',function(){

由于.register-btn不驻留在DOM(动态元素)上,因此无法直接绑定事件.

Since .register-btn does not reside on the DOM(dynamic element), you cannot bind the event directly.

对于动态元素,语法为:

For dynamic elements, the syntax is:

$(parentselector).on('event', 'selector', yourFunction)

请注意,parentselector必须是Non-dynamic always DOM present element

Note that parentselector needs to be a Non-dynamic always DOM present element