weixin_33713350 2011-09-27 04:57 采纳率: 0%
浏览 76

为什么jQuery Ajax .html不起作用?

success: function(json) {
            for (var i = 0; i < json.length; i++) {
        var response = json[i];
         $('#rv-container').html('<p>' + response.name + '</p>' + '<span>' + response.id + '</span>');
    }
        $('#history_tracking').hide();

        }

在success回调中,$(#rv-container).html()不起任何作用,但.prepend会起作用。

为什么jQuery在success回调中不允许 .html?通过ajax加载的html不断堆积已加载数据的顶部,因此,它不会替换#rv-container中当前的数据。

HTML:

<div id="bottom-toolbar">
  <div id="rv-facet">
    <div id="rv-fix">
      <li id="rv-title">
        Recently Viewed <span class="total_viewed"></span>
        <div id="rv-total" style="float:right; margin-right:25px;"></div>
      </li>
    </div>
    <div id="rv-content">
      <div id="rv-container">
        <div id="history_tracking"></div>
      </div>
    </div>
  </div>
</div>

有可以用prepend替换div的内容吗?

  • 写回答

2条回答

  • weixin_33725515 2011-09-27 05:03
    关注

    You are calling it in a loop, so obviously it makes a difference whether you are resetting the HTML content over and over (.html()) or prepending more and more to it (.prepend())?

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!