jquery ui 动态表 onclick 事件不起作用
我需要在 jquery 中显示动态表。单击表数据时,应在下面的文本字段中设置值。
我可以知道如何从动态表中捕获名称并将其设置到文本字段中
$(document).ready(function() {
//Retrieve the JSON data from the server using AJAX
$('#AJAXButton').click(function() {
$.getJSON('ajax/ajaxtest.js', function(data) {
processJSON(data);
});
});
//Process and display the JSON data
function processJSON(data) {
var output = '<table><tr><th>Name</th><th>Platform</th></tr>';
//Loop through the Languages
$(data.Languages).each(function(index, element) {
output += '<tr><td class="clickable">' + element.Name + '</td>' +
'<td class="clickable">' + element.Platform + '</td></tr>';
});
output += '</table>';
$('#AJAXDiv').html(output);
}
$("tr.clickable").live("click", function() {
$("#name").append(?);
});
});
<div id="AJAXDiv" style="width:400px; height:600px; background-color:#ddd; border:1px solid black">
</div>
<div>
<label for="name">Created by: </label> <input id="name" />
</div>
I have requirement to display dynamic table in jquery. On clicking on table data the value should set in below text field.
May I know how to capture the name from dynamic table and set into text field
$(document).ready(function() {
//Retrieve the JSON data from the server using AJAX
$('#AJAXButton').click(function() {
$.getJSON('ajax/ajaxtest.js', function(data) {
processJSON(data);
});
});
//Process and display the JSON data
function processJSON(data) {
var output = '<table><tr><th>Name</th><th>Platform</th></tr>';
//Loop through the Languages
$(data.Languages).each(function(index, element) {
output += '<tr><td class="clickable">' + element.Name + '</td>' +
'<td class="clickable">' + element.Platform + '</td></tr>';
});
output += '</table>';
$('#AJAXDiv').html(output);
}
$("tr.clickable").live("click", function() {
$("#name").append(?);
});
});
<div id="AJAXDiv" style="width:400px; height:600px; background-color:#ddd; border:1px solid black">
</div>
<div>
<label for="name">Created by: </label> <input id="name" />
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看这个小提琴,如果这不是你想要的,请告诉我。
Take a look at this fiddle and let me know if it's not what you intended.
您说您希望在单击该行时发生该事件,因此您只需将“clickable”类放在您的行上,而不是每个“td”。然后,单击处理程序可以访问该行中的第一个“td”(您所在的名称)。
IE。 演示
You say you want the event to happen when the row is clicked, so you just put the 'clickable' class on your row instead of every 'td'. The click handler can then access first 'td' within that row (the name that you are after).
ie. Demo