追加的html代码使用jquery的click事件无效
在动态增加的内容中包含点击按钮,但是通过jquery的click无法触发

$('#addone').click(function () {
var appendStr=
" \\n" +
" \\n" +
"
\\n" +
" \\n" +
"
\\n" +
" \\n" +
" ";
$("#firstone").append(appendStr)
});
$("#firstone").on("click",".deleteone",function () {
alert(1234)
$(this).closest(".layui-row").remove();
})比如通过id为addone的按钮向id为firstone的p中动态加入一个包含class为deleteone的按钮的p,点击这个按钮可以触发事件,但是发现
$('.deleteone ').click(function () {
})没任何反应
现在需要使用到jquery的on事件,通过把click事件向元素中的指定内容附加
$("#firstone").on("click",".deleteone",function () {
alert(1234)
$(this).closest(".layui-row").remove();
})推荐教程:《JS教程》
分享标题:追加的html代码使用jquery的click事件无效
本文链接:http://www.jxjierui.cn/article/cgpodc.html


咨询
建站咨询
