jquery 生成的dom无法触发click事件的解决方案

admin4年前前端技术953


原因是程序找不到此节点在jQuery中有“向未来的元素添加事件处理程序”方法说明,也正是动态创建元素无法触发事件的原因所在。

正确的写法应该是:

$(‘父元素’).on(‘click’,’动态的子元素’,function(){});

或者通过行内写法:

<div onclick="函数名称()"></div>


相关文章

让TD 与div自动换行的css方法

word-wrap: break-word;  word-break: break-all; white-space: normal;...

ubbedit实现遍历绝对目录绑定cookie查询以前上传的图片

ubbedit实现遍历绝对目录绑定cookie查询以前上传的图片

设置cookie ,$user_id=$_COOKIE["user_email"];设置path   , $path =  "/"...

H5实现移动端禁止页面缩放(适用Android和IOS)

要实现Android和IOS浏览器禁止页面缩放,通用的设置方式是给HTML页面设置meta标签来实现,具体添加标签内容如下:<meta name="viewport"...

原生javascrip 复制功能

兼容chrome FIrfox IE 下载地址000.zip代码如下:<!DOCTYPE html> <html> <head> &nbs...

Navigate down the menu through jquery development

The core knowledge is to use jquery's hover method to achieve, The animation effe...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。