【问题标题】:jQuery dynamic content loaded via Ajax通过 Ajax 加载的 jQuery 动态内容
【发布时间】:2013-05-01 14:52:07
【问题描述】:

大家好,我正在尝试关闭页面加载时显示的 div。但是,这样做:

jQuery(document).ready(function () {
   jQuery('#moreDetailsTable').slideUp("fast", function () {});
});

页面加载时似乎不会关闭它,因为它是通过 PHP 代码使用 ajax 动态填充的。

ajax调用的php是这样的:

echo '<div id="moreDetailsTable" class="widefat fixed comments">
    Testing this out<br />
    Testing this out<br />
    Testing this out<br />
    Testing this out<br />
    Testing this out<br />
</div>
   ect ect.....

我知道代码可以工作,因为我只是这样做:

jQuery(document).on('click', '#moreDetailsTable', function() {
    jQuery('#moreDetailsTable').slideUp("fast", function () {
        console.log('done');
    });
});

一旦我点击它,它就会向上滑动。

我如何调用 .slideUp,因为它是动态填充的,而不是在开始的页面上?

【问题讨论】:

  • @Jordan 回答这个问题,这样我就可以给你信用了,拜托。
  • 你能显示你的ajax代码吗?

标签: php jquery ajax


【解决方案1】:

请参阅jQuery.ajaxComplete() 事件处理程序。这会做你想做的。

例子:

jQuery(document).ajaxComplete(function () {
   jQuery('#moreDetailsTable').slideUp("fast", function () {});
});

【讨论】:

  • 再次感谢乔丹的帮助。
  • 没问题!很高兴我能帮上忙。
【解决方案2】:

ajax 返回时调用该函数。加载内容后。比如:

$('.ajaxLoading').show();
    $.ajax({
    type:'POST',
    url:'url',
    dataType: "json"}).done
    (function(response){
        alert(response.message);
        $('.ajaxLoading').hide();
        //window.location = "/dash_board";
            $('#moreDetailsTable').slideUp("fast", function () {});
    }).fail(function(response,textStatus){
        alert('Something goes wrong. Please try again.');
        $('.ajaxLoading').hide();
        //alert(textStatus);
    });

【讨论】:

  • 感谢重播我的问题,何塞。
猜你喜欢
  • 1970-01-01
  • 2011-04-19
  • 2011-05-21
  • 2013-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-26
  • 1970-01-01
相关资源
最近更新 更多