我有一個函數,它需要一些數據並生成一個覆蓋窗口的排序。這會得到一個關閉窗口的按鈕。我無法弄清楚爲什麼,.click永遠不會被解僱(甚至從未發生過警報)關閉按鈕。這裏是相關的功能。Jquery添加HTML並使用點擊附加項目刪除
//This is what gets appended
function createOpponentMenu(item1, item2) {
$('<div id="matchMenu"><div id="vs">VS</div><div id="opponent1">' + item1.media + '<div id="vote1">VOTE</div><div class="desciption-container"><h2 class="match-hed">' + item1.name + ' | <span style="font-family:SupriaSans-Regular">' + item1.when + '</span></h2><p class="match-text"><span style="color:red;font-family:SupriaSans-Bold">OFFENSE:</span> ' + item1.offense + '</p><p class="match-text"><span style="color:green;font-family:SupriaSans-Bold">OUTCOME:</span> ' + item1.outcome + '</p></div></div><div id="opponent2">' + item2.media + '<div id="vote2">VOTE</div><div class="desciption-container"><h2 class="match-hed">' + item2.name + ' | <span style="font-family:SupriaSans-Regular">' + item2.when + '</span></h2><p class="match-text"><span style="color:red;font-family:SupriaSans-Bold">OFFENSE:</span> ' + item2.offense + '</p><p class="match-text"><span style="color:green;font-family:SupriaSans-Bold">OUTCOME:</span> ' + item2.outcome + '</p></div></div><div id="matchup-close">Close X</div></div>').appendTo('#bracket-container').fadeIn("slow");
}
// This decides what to append
$(".matchup-container").click(function() {
for(var i=0; i<matchups.length; i++) {
if(this.id == "matchup" + (matchups[i].match).toString()){
createOpponentMenu(matchups[i].id1, matchups[i].id2);
}
}
});
//now I just want to kill the whole thing on close click
$('#matchup-close').click(function() {
alert("wtf");
$('#matchMenu').fadeOut("slow").remove();
});
謝謝,這是有道理的。我在JS中做了很多這些東西的新手。 – user1310774