javascript - innerHTML 函数不会改变我的 td 的内容
问题描述
我有一个几乎可以工作的 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';
我搜索过 :
但是我什么都没想到...
解决方案
如果你使用 jQuery,正确的语法是
$("#SommePour").html("What you want to add");
它应该是.html
推荐阅读
- android - ListView 与 CoordinatorLayout 中的 SearchView 重叠
- php - 为什么我的一个多站点 Wordpress 作为符号链接不能正常工作?
- python - Docker 在 Apple M1 上构建 python 应用程序错误“没有为 spacy==2.3.2 找到匹配的分布”
- google-sheets - 如何根据日期查找人数
- laravel - 如何在 app.js 之外使用 VueJs 组件
- python - 将熊猫数据框转换为字典列表
- flutter - 有没有办法在相机移动结束后运行功能?(地图框)
- python - 如何使用 django 加载博客网站的文章页面?
- flutter - 全球密钥
().currentState.context 在推送时返回 null - python - 在 Python 中规范化 JSON