[英]JavaScript not working after AJAX call - AJAX tabs
I trying to make a submenu with the ability to change the page content without the refreshing, so I used AJAX tabs to call an external htm. 我试图使子菜单具有无需刷新即可更改页面内容的功能,因此我使用AJAX选项卡调用了外部htm。 The tabs are working, but I have a JavaScript inside my external htm which makes the white navigation arrows work, and also crossfades the content, which is not working. 选项卡有效,但是我在外部htm中有一个JavaScript,该JavaScript使白色导航箭头有效,并且使内容交叉淡入淡出,从而无法正常工作。 How do I fix this? 我该如何解决?
I am talking about this particular page - "Nick 101" 我说的是这个特定页面-“尼克101”
www.adigitalgoodie.com/about.htm www.adigitalgoodie.com/about.htm
It is supposed to work like it does on the frontpage 它应该像在首页上一样工作
www.adigitalgoodie.com/index.htm www.adigitalgoodie.com/index.htm
This is the JavaScript inside the htm, fetched via AJAX, which isn't working: 这是htm内的JavaScript,无法通过AJAX提取:
<script type="text/javascript">
$('.contentnavright').click(function(){
$('.contenttext1').fadeOut();
$('.contenttext2').fadeIn();
$('.contentnavleft').css('opacity', '1');
$('.contentnavleft').css('-moz-opacity', '1');
$('.contentnavleft').css('filter', 'alpha(opacity=100)');
$('.contentnavright').css('opacity', '0');
$('.contentnavright').css('-moz-opacity', '0');
$('.contentnavright').css('filter', 'alpha(opacity=0)')
});
$('.contentnavleft').click(function(){
$('.contenttext1').fadeIn();
$('.contenttext2').fadeOut();
$('.contentnavleft').css('opacity', '0');
$('.contentnavleft').css('-moz-opacity', '0');
$('.contentnavleft').css('filter', 'alpha(opacity=0)');
$('.contentnavright').css('opacity', '1');
$('.contentnavright').css('-moz-opacity', '1');
$('.contentnavright').css('filter', 'alpha(opacity=100)')
});
</script>
It seems that script is same for all pages. 似乎所有页面的脚本都是相同的。 As such you can just put it in the main html, and use the live/on jquery approach: 这样,您可以将其放在主html中,并使用实时/在线jquery方法:
$("#container").on("click", ".contentnavright", function(){whatever});
将该代码放入函数中,并在您的ajax请求完成后调用该函数
$('.contentnavleft').click(myFunc);
function myFunc(){
$('.contenttext1').fadeIn();
$('.contenttext2').fadeOut();
$('.contentnavleft').css('opacity', '0');
$('.contentnavleft').css('-moz-opacity', '0');
$('.contentnavleft').css('filter', 'alpha(opacity=0)');
$('.contentnavright').css('opacity', '1');
$('.contentnavright').css('-moz-opacity', '1');
$('.contentnavright').css('filter', 'alpha(opacity=100)')
}
then, when you finished your ajax request, you put $('.contentnavleft').click(myFunc);
然后,当您完成ajax请求时,您放入$('.contentnavleft').click(myFunc);
to bind again the function to the .contentnavleft element. 将功能再次绑定到.contentnavleft元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.