我的问题是,我得到一个 html 文本操作系统字符串,无论它来自 jquery 是什么,但是当我将它打印在 div 元素内时,它不会清除里面的旧数据。
div就是这么简单
<div id=table runat=server>
我的脚本在这里
function send(inputa, inputb) {
var dataString = JSON.stringify({
Id: inputa,
Opt: inputb
});
$.ajax({
type: "POST",
url: "my.aspx/myfunction",
data: dataString,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert(result.d); // here i can see calue is good
$("#ctl00_ContentPlaceHolder2_tablo").empty(); // here i try to clean
$("#ctl00_ContentPlaceHolder2_tablo").html(result.d);
},
error: function () {
alert("Problem Occured");
}
});
}
请告诉我这里有什么不好的地方。我尝试了 html text val 的所有功能,我想我需要更多的东西。我的输出也有旧值。
最佳答案
您的<div>
是:
<div id=table runat=server>
所以而不是
$("#ctl00_ContentPlaceHolder2_tablo").empty(); // here i try to clean
$("#ctl00_ContentPlaceHolder2_tablo").html(result.d);
使用正确的id
:
$("#table").empty(); // this is not necessary
$("#table").html(result.d); // this will clear the existing content
关于javascript - 使用 Jquery 覆盖 div 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25835838/