在动态增加的内容中包含点击按钮,但是通过jquery的click无法触发$('#addone').click(function () {
var appendStr=
"
\n" +"
\n" +
"
\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教程》