jquery无法使div为空

在我的ASP.NETMVC4应用程序中,我正在加载当前页面中的部分视图.代码成功地将所需的部分视图加载到当前页面中.但是,在向服务器发送jQuery AJAX请求之前,我正在尝试清除div.但div并未清除.旧内容仍在那里,直到新内容到达.我的密码是这样的-

选择 | 换行 | 行号
  1. <script type="text/javascript">
  2.     $(document).ready(function () {
  3.         $(".mainnav a").click(function (e) {
  4.             e.preventDefault();
  5.             var url = $(this).attr('href');
  6.             if (url != '#') {
  7.                 $('#PartialContent').empty(); //not working 
  8.                 $('#PartialContent').html(''); //not working 
  9.                 $('div#PartialContent').children().remove(); //not working 
  10.                 $.get(url, function (response) {
  11.                     $('#PartialContent').html(response);
  12.                 });
  13.             }
  14.         });
  15.     });
  16. </script>

有什么办法解决这个问题吗?

# 回答1


将$('#PartialContent').html("");放入$.get函数中.

选择 | 换行 | 行号
  1.  $.get(url, function (response) {
  2.    $('#PartialContent').html("");
  3.    $('#PartialContent').html(response);
  4.  });
  5.  

标签: Javascript

添加新评论