gpt4 book ai didi

javascript - JQuery onClick 自动生成的表不起作用

转载 作者:行者123 更新时间:2023-11-28 19:58:31 24 4
gpt4 key购买 nike

我正在从通过 $.getJSON 检索的 JSON 数据自动填充表格。打电话。

当我点击 ant 时,我想显示一个警报。

这是我的代码。

<body>
<div id="container">

<div id="header">
<img id="titleimage" border="0" src="images/title.png">
</div>

<div id="sub-container">
<div id ="video_container">
<h1>HTML5 local video file player example</h1>
<div id="message"></div>
<input type="file" accept="video/*"/>
<video id="match_video" controls autoplay></video>
</div>
<div id="log_container">
<table id="chart"class="masterTooltip" title="RaboPro12 League Table">
<tr>
<th>Time</th>
<th>Event</th>
<th>Name</th>
</tr>
</table>
</div>
<div id="stats_container"></div>
</div>

</div>
</body>

JQuery

$(document).ready(function() {

$.getJSON("php/getLog.php", function(result) {
//var data = $.parseJSON(result);

$.each(result, function(i, obj) {
var fname = obj.first_name;
var sname = obj.surname;
var allName = fname + " " + sname;
var time = obj.time;
var event = obj.event;
$('<tr id ="row"></tr').html('<td>' + time + '</td><td>' + event + '</td><td>' + allName + '</td>)').appendTo('#chart');
});
});

$('.row').click(function() {
alert("row clicked");
});

});

这是填充表格后的 html 片段。

enter image description here

由于某种原因未触发行点击。

谢谢

最佳答案

所有行的 ID 均为“row”,但您的目标是 jQuery 中的“row”类。将 ID 更改为类即可工作。

关于javascript - JQuery onClick 自动生成的表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22083822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com