Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript innerHTML函数不更改my td的内容_Javascript_Html_Razor - Fatal编程技术网

Javascript innerHTML函数不更改my td的内容

Javascript innerHTML函数不更改my td的内容,javascript,html,razor,Javascript,Html,Razor,我有一个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"> Som

我有一个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>
我搜索:


但是我没有想到什么…

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

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


来源:

您混合了jQuery对象和DOM属性。它应该是
$(“#SommePour”).html(…)
一旦我们到了@Barmar,是否允许我使用substring(),或者这将是相同的?当然可以。不管你如何得到一个字符串,它都是一样的。但是为什么你要对空字符串调用
.substring()
?我认为这是Razor在做的,而不是浏览器。
html
是一个函数,你必须调用它。没错,我的错误,我会更正答案。
$("#SommePour").html("What you want to add");