gpt4 book ai didi

javascript - 如何将 id 添加到 @Html.DisplayFor

转载 作者:行者123 更新时间:2023-11-29 16:06:05 25 4
gpt4 key购买 nike

我正在尝试将 id 添加到

@Html.DisplayFor(model => model.ScreenWidth, new { @id = "width"})

然后使用

document.getElementById("width").innerHTML = w;

为什么它不起作用?

最佳答案

DisplayFor 助手不生成任何 HTML 标签,它只是输出格式化的文本。所以你不能给它添加 id 属性。您可以做的是将其包装在标签(div 或 span)中:

<div id="width">
@Html.DisplayFor(model => model.ScreenWidth)
</div>

然后能够操作这个标签的内容:

document.getElementById("width").innerHTML = w;

关于javascript - 如何将 id 添加到 @Html.DisplayFor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41930753/

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