[英]jquery load() after ajax page is loaded - howto
i have following lines included at the bottom of my index.php: 我在index.php的底部包含以下几行:
<script type="text/javascript" language="javascript" src="class/jquery-1.4.3.min.js"> </script>
<script type="text/javascript" language="javascript" src="class/jquery.nivo.slider.pack.js"></script>
<script type='text/javascript' language='javascript'>
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>
problem lies in $(window).load
... 问题在于$(window).load
...
index.php's body is updated onload through ajax call which delivers div#slider upon matching. index.php的主体通过ajax调用在加载时更新,该调用在匹配时提供div#slider。 this makes it nivoSlider()
not executing. 这使得nivoSlider()
无法执行。 do you have any trick to make this thing work. 你有什么办法使这件事起作用吗? i do prefer non-jquery way around it, but at the end of the day anything helps. 我确实更喜欢非jquery的方式,但最终还是有帮助。
many thanks 非常感谢
Add the call in the callback for the AJAX load. 在AJAX加载的回调中添加呼叫。
$('.something').load( 'http://www.example.com/foo', function() {
$(this).find('#slider').nivoSlider();
});
Example using your code (for body): 使用您的代码的示例(针对主体):
$(function() { // run on document ready, not window load
$('#content').load( 'page.php?c=2&limit=5', function() {
$(this).find('#slider').nivoSlider();
});
});
For link: 对于链接:
<!-- updates links like so -->
<a class='nav' href='page.php?category=art&limit=5&c=1'>art</a>
// in the same document ready function
$('a.nav').click( function() {
var $link = $(this);
$('#content').load( $link.attr('href'), function() {
$(this).find('#slider').nivoSlider();
$link.addClass('selected'); // instead of setting bg directly to #828282;
});
return false; // to prevent normal link behavior
});
Would you not want to use $(document) rather than $(window)? 您是否要使用$(document)而不是$(window)?
$(window).load(function() { $('#slider').nivoSlider(); });
or shorthand 或速记
$(function() { $('#slider').nivoSlider(); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.