gpt4 book ai didi

javascript - innerHTML 函数不会更改我的 td 的内容

转载 作者:行者123 更新时间:2023-12-02 23:03:49 32 4
gpt4 key购买 nike

我有一个ajax函数,几乎可以工作,但不能工作的是当它到达innerHTML函数时。当成功部分达到时,我试图更改 td 内的文本。

在我的 MVC 项目的 .cshtml 文件中,我有这个简单的 HTML 和 JS:

// This td is not part of a loop, it is just inside a single table and tr

<td id="SommePour" style="min-width: 480px;" colspan="2">
Somme pour @(Model.PbSelected?.Insert(4,"-").Insert(3,"-") ?? "000-0-00000")
</td>


<script>
function NouveauTotal(noCompt9) {
$.ajax({
url: '@Url.Action("ChangeSousTotaux", "Explorer")',
type: 'post',
data: {
postBudg9: noCompt9
},
success: function (result) {

$("#SommePour").innerHTML = "<span>Somme pour " + '' + noCompt9 + ''.substring(0, 3) + "-" + '' + noCompt9 + ''.substring(3, 4) + "-" + '' + noCompt9 + ''.substring(4, 9) + "</span>";
}
});
}
</script>

我什至尝试过:

$("#SommePour").innerHTML = 'yo';

我搜索过:

Changing td element text using Javascript

.substring error: "is not a function"

但我什么也没想到......

最佳答案

如果您使用 jQuery,正确的语法是

$("#SommePour").html("What you want to add");

它应该是.html

来源:https://www.w3schools.com/jquery/html_html.asp

关于javascript - innerHTML 函数不会更改我的 td 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57681750/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com