更新时间: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