$(function() {
$.getJSON("companies.json", function(response) {
var html = '<table id="tbl">';
response.businesses.forEach(function(row) {
html += '<tr><td><a href="#" class="move" idname="' + row.id + '">' + row.id + '</a></td><td>' + row.name;
});
html += '</table>';
$("#tabledata").html(html);
});
$(".move").click(function() {
var $id = $(this).attr("idname");
$.getJSON("companies.json", function(response) {
$.map(response.businesses, function(obj) {
if (obj.id == $id)
console.log(obj);
return obj; // or return obj.name, whatever.
});
});
});
});
HTML不觸發?A HREF點擊jQuery的
你能否提供HTML以及 –
你試過''('。move')。on('click',function(){})' –
可能重複[Event binding on dynamic created elements?] (http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – JJJ