表超链接上的Jquery Click事件不适用于来自ajax调用的表数据,但适用于输入的静态数据。
Fiddle
$("a").click(function (e) {
var txt = $(e.target).text().replace(/\s/g, "%20");
alert(txt);
});
最佳答案
它无法工作,因为您正在动态添加数据。
使用事件委派。.on()
方法将事件处理程序附加到jQuery对象中当前选定的元素集。
写入:
$(".table").on("click","a",function (e) {
var txt = $(e.target).text().replace(/\s/g, "%20");
alert(txt);
});
Updated fiddle here.
Refer this document.