我使用jQuery在.item-table中添加附加内容。
添加代码后,html以所有正确的css样式完美地呈现内容。问题是,我在.js中编写的代码不起作用。
现在有两个按钮:1)按钮,2)通过jQuery添加的按钮
.click在第1种情况下工作,但在2上不起作用)
你需要重新应用js文件吗?或者还有别的东西可以解决这个问题呢?
与“..item删除-按钮”关联的单击事件
$('.item-delete-button').click(function(){console.log("test")};添加到html中的代码。
$('.item-table').append(
'<div class="item-table-row col-xs-12">'+
'<div class="item-delete col-xs-2">'+
'<button type="button" class="item-delete-button btn btn-warning col-xs-6">Delete</button>'+
'</div>'+
'</div>'
);在HTML启动时
<div class="row item-table">
<div class="item-table-row col-xs-12">
<div class="item-delete col-xs-2">
<button type="button" class="item-delete-button btn btn-warning col-xs-6">Delete</button>
</div>
</div>
</div>发布于 2014-11-30 16:21:28
您需要将事件委托用于动态html,将事件绑定到存在于DOM上的父元素(使用.on):
$('.item-table').on("click", ".item-delete-button", function(){
console.log("test")
});https://stackoverflow.com/questions/27215329
复制相似问题