jquery无法使div空 [英] jquery fails to make a div empty
本文介绍了jquery无法使div空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的asp.net mvc 4应用程序中,我正在当前页面中加载局部视图。代码在
In my asp.net mvc 4 application, i am loading a partial view in current page. The code successfully loads the desired partial view in
<div id="PartialContent"></div>
。但是,在向服务器发送jquery ajax请求之前,我正在尝试清除div。但是div并没有清算。
旧内容仍然存在,直到新内容到来。这是我的代码 -
on the current page. But, before sending jquery ajax request to the server, i am trying to clear the div. But the div is not clearing.
The old content is still there until the new content arrives. Here is my code-
$(document).ready(function () {
$(".mainnav a").click(function (e) {
e.preventDefault();
var url = $(this).attr('href');
if (url != '#') {
$('#PartialContent').empty(); //not working
$('#PartialContent').html(''); //not working
$('div#PartialContent').children().remove(); //not working
$.get(url, function (response) {
$('#PartialContent').html(response);
});
}
});
});
任何想法?
any idea?
推荐答案
( document )。ready( function (){
(document).ready(function () {
(& quot ; .mainnav a& quot;)。click( function (e){
e.preventDefault();
var url =
(".mainnav a").click(function (e) { e.preventDefault(); var url =
( this )。attr(&#39; href&# 39;);
如果(url!=&#39;#&#39;){
(this).attr('href'); if (url != '#') {
这篇关于jquery无法使div空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文