在已经使用.load()的div上使用jquery效果

时间:2012-08-25 01:17:08

标签: jquery load

我有一些jQuery效果(slideUp()等)可以正常工作。

现在我.load()setTimeout之后,效果不再有效。

这是因为在我假设的.load()之前,div并不存在。

效果和.load()都在同一个JS文件中,并且都包含在jQuery(document).ready(function($) { /*They are here*/ });

如何在.load()之后调用这些效果?

1 个答案:

答案 0 :(得分:1)

由于你没有发布代码设置.slideUp()方法等。我假设你有类似的东西:

$(function) () {

   $('.class').slideUp(300);
   $('.wrapper').load('someurl.html'); // this loads some elements with .class
   // these elements won't get slideUp applied because they are not in the DOM at the time of the slideUp call


)};

您需要在加载回调中设置事件/功能:

$('#result').load('ajax/test.html', function() {
  //apply events to new elements
  $('.class').slideUp(300);  // this would be inside a click event I'm assuming
});

或者如评论中所提到的......你可以(应该)使用.on来处理委托。我的观点是尝试帮助您了解未应用事件的原因

相关问题