在我的问题有意义之前,我需要解释几件事。在我的第一页上,我有一个主 div,我使用 jquery load() 方法从另一个页面加载标记。我正在加载的 html 链接到我的脚本所在的 .js 页面。js 页面是我操作主 div 内容的地方。在我的 js 页面上,我循环遍历从数据库中提取的变量数组,并将它们 append() 到主 div。在 for 循环中,我将每一行包装在自己的 div 中并包含一个锚标记。锚标记是我想要附加 click() 方法的对象,因此我可以在单击它后调用一个函数。我已经尝试过 parent > child 选择器等,但对于锚标记没有任何作用。我的代码:
//this is the query to my parse database
query.find({
success: function(results) {
for (i = 0; i < results.length; i++){
activity = results[i].get("activity");
scene = results[i].get("location");
neighborhood = results[i].get("neighborhood");
date = results[i].get("date");
details = results[i].get("details");
time = results[i].get("time");
search.push([activity, scene, neighborhood, date, details, time]);
for (i = 0; i < search.length; i++) {
//append each row of results to mainDiv inside of their own div with an anchor tag at the end of each row.
//when the anchor tag is clicked I want to call a function, but none of the selectors I've tried have worked.
$('#mainDiv').append("<div id='event'>" + search[i].join(' ') + "<a href='#' id='interested'>Interested?</a></div>");
}
};// closes for loop
},//closes success function
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
}); //closes find