为什么点击事件绑定不上???
AJAX请求完数据,动态填充表格,表格中有按钮。
$('#wh_InOut>tbody').append('<tr>'
+ '<td>' + this.Ower + '</td>'
+ '<td>' + this.Region + '</td>'
+ '<td class="text-right">'
+ '<button onclick="clickWh_InOut(event);" data-ower="' + this.Ower + '" data-epc="' + this.EPC + '" data-status="' + this.Status + '" class="wh_InOut_Bt btn-info btn btn-xs" data-toggle="modal" data-target="#myModalWHInOut">' + (this.Status === 0 ? '你好' : '不好') + '</button>'
+ '</td>'
+ '</tr>');
});
用” $('.wh_InOut_Bt').click“不行,因为Button是Ajax请求回来,手动添加的HTML元素,$('.wh_InOut_Bt')获得不了元素。
如果用onclick="clickWh_InOut(event);"事件,然后在$(function () {})中定义 var clickWh_InOut = function (event) {})定义一个函数,却提示“”WHInOut.aspx:1 Uncaught ReferenceError: clickWh_InOut is not defined
at HTMLButtonElement.onclick (WHInOut.aspx:1)“”
为什么呢??? 之前解决过这个问题,忘记了。求大师指教。