在動(dòng)態(tài)增加的內(nèi)容中包含點(diǎn)擊按鈕,但是通過jquery的click無法觸發(fā)
$('#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中動(dòng)態(tài)加入一個(gè)包含class
為deleteone
的按鈕的p,點(diǎn)擊這個(gè)按鈕可以觸發(fā)事件,但是發(fā)現(xiàn)
$('.deleteone ').click(function () { })
沒任何反應(yīng)
現(xiàn)在需要使用到j(luò)query的on事件,通過把click事件向元素中的指定內(nèi)容附加
$("#firstone").on("click",".deleteone",function () { alert(1234) $(this).closest(".layui-row").remove(); })
推薦教程:《JS教程》
分享名稱:追加的html代碼使用jquery的click事件無效
網(wǎng)站地址:http://weahome.cn/article/cgpodc.html