[英]Content loaded with jQuery .load() doesn't function
I am having some porblems with getting JQuery to load an html page. 我在让JQuery加载html页面时遇到一些麻烦。 I use JQuery to load this page vvv
我使用JQuery加载此页面vvv
<a class="codaw" href="#"><img id="codawx_img" src="img/codawx.png" alt="Call of Duty:Advanced Warfare" style="height:150px;"></a>
<script>
$('a.codaw').on('click', function(e){
e.preventDefault();
$('#container').remove();
$('#content').load('second.html'+'#content').hide().fadeIn('slow');
});
</script>
and that page loads fine but that ^^^ jquery function wont load the second html content it just loads the href. 并且该页面加载良好,但是^^^ jquery函数将不会加载第二个html内容,而只会加载href。
I don't know what i am doing wrong here if some one could please share some knowledge i would be thankful. 我不知道如果有人可以分享一些知识,我会在这里做错我会很感激的。
You may need event delegation. 您可能需要事件委托。 Try this:
尝试这个:
<script>
$(function(){
$(document).on('click', 'a.codaw', function(e){
e.preventDefault();
$('#container').remove();
$('#content').load('second.html'+'#content').hide().fadeIn('slow');
});
});
</script>
Reference: 参考:
http://davidwalsh.name/event-delegate http://davidwalsh.name/event-delegate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.