jQuery Ajax 替换而不是追加
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1675215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ajax replace instead of append
提问by shaiss
回答by Marek Karbarz
you could empty the element before you append
你可以在追加之前清空元素
$("#results").empty().append(myHtml);
or use the html
method
或使用html
方法
$("#results").html(myHtml)
回答by Greg
Just change
只是改变
$('#results').append(myHtml);
to
到
$('#results').html(myHtml);
回答by zkaptic
ok, last entry 2009, but if the problem still exist:$("#results").replaceWith(yourContent)
好的,最后一次进入 2009 年,但如果问题仍然存在:$("#results").replaceWith(yourContent)
回答by Namesh Silva
Empty function before your append or prepend function.
在 append 或 prepend 函数之前清空函数。
I tried this & it worked --->
我试过了,它奏效了--->
frame is id selector & it append image.
frame 是 id 选择器 & 它附加图像。
$("#frame").empty().append('<img src="" >' );