我编写的脚本如下:
<script type="text/javascript">
$(document).ready(function(){
$("#Click").click(function(){
var data1 = new Object();
data1.name = $('#databases').val();
$.ajax({
url : "form_submit",
type : 'POST',
data : data1,
dataType : "text",
success : function(data){
data = JSON.parse(data);
var output="<table id=tableStyle>";
output+="<tr>" + "<th>" + "REPORTSUITE_ID" + "</th>" + "<th>" + "REPORTSUITE_NAME" + "</th>" + "<th>" + "STAGING_DATABASE" + "</th>" + "<th>" + "DWH_DATABASE" + "</th>" + "</tr>";
for (var i in data)
{
output+="<tr>" + "<td>" + data[i].REPORTSUITE_ID + "</td>" + "<td>" + "<button type = \"buttion\" id =\"tableList\">" + data[i].REPORTSUITE_NAME + "</button>" + "</td>" + "<td>" + data[i].STAGING_DATABASE + "</td>" + "<td>" + data[i].DWH_DATABASE + "</td>" + "</tr>";
}
output += "</table>";
document.getElementById("placeholder").innerHTML=output;
}
});
});
});
$("#tableList").click(function(){
alert("this is data");
});
</script>
在点击id = tableList的按钮时,我想要显示带有“this is data”消息的警报,但它不会显示任何内容。 我也试着粘贴与不同标签之间的id tableList按钮相关的代码,但它仍然无法正常工作。 请帮忙
答案 0 :(得分:0)
您使用了上述问题的事件授权,如下所示:
<script>
$(document).on("ready",function(){
$("#placeholder").on("click","button",function(event){
alert("id is " + this.id + "for database " + $('#databases').val())
})
});
</script>
正确传递了该值。谢谢你的指针。