【发布时间】:2013-02-18 16:11:34
【问题描述】:
使用 Ajax 将以下 HTML 加载到 HTML 页面的 div 中,我想在用户单击该 HTML 中的 a.start-btn 时执行代码,由于某种原因它没有检测到那里的点击,我'我试过 .live 但没有用。有什么问题?谢谢
<div class="map">
<div class="game-step1">
<div class="note">
<h5>Day 5</h5>
<p>Today is the 5th day of our trip around the world... We have already visited Rome, Istambul, Kenya and Maldives.<br/><br/>
<strong>Ready to guess what will be our next destination?</strong></p>
</div>
<img src="img/route1.png" class="route route1"/>
<a href="#" class="game-button start-btn" >Start the Game »</a>
</div>
</div>
function showReadyMsg() {
$('.game-step1').animate({left:'-886px'}, 500);
console.log('showReadyMsg called')
}
$(".start-btn").live("click", function(){
console.log('button clicked')
showReadyMsg();
});
【问题讨论】:
-
问题在于他没有将任何函数绑定到通过 AJAX 加载的项目,除非您在回调函数中明确显示,否则 DOM 看不到它。我在下面的答案中详细说明了。