jQuery:如何在添加新内容之前清除元素? [英] Jquery: How to clear an element before appending new content?
本文介绍了jQuery:如何在添加新内容之前清除元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的jquery代码
This is my jquery code
$.ajax({
url: "PopUpProductDetails.aspx",
cache: false
}).done(function (html) {
$("#dialog").append(html);
});
第一次,它工作正常.它显示 PopUpProductDetails.aspx 页的内容.但是,此后,如果再次单击,我将获得两次相同的内容,依此类推.我认为问题在于,在添加新内容之前,我需要先清除 dialog 元素.
The first time, it works just fine. It display the content of the PopUpProductDetails.aspx page. But, after that, If I click again, I get twice the same content, and so forth. I believe the problem is that I need to clear the dialog element first, before appending new content.
我该怎么做?
推荐答案
.append()
将html附加到现有html字符串的末尾,使用.html()
替换#dialog
中当前的内容.
.append()
appends html to the end of existing html string, use .html()
to replace what's currently inside of #dialog
.
这篇关于jQuery:如何在添加新内容之前清除元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文