gpt4 book ai didi

javascript - 如何在 MVC 上将 id 设置为 Html.TextBox 项目

转载 作者:IT王子 更新时间:2023-10-29 03:14:13 26 4
gpt4 key购买 nike

我试图通过 javascript 捕获文本框元素,以便将文本放入其中。那么如何将 id 设置为文本框呢??

        <tr>
// Id to this textbox
<td>@Html.TextBoxFor(item => item.OperationNo)</td>
</tr>

然后用JS把文字放进去

                            // 
document.getElementById("Textbox id").Text= " Some text " ;

最佳答案

您可以像这样设置文本框的 ID。

@Html.TextBoxFor(item => item.OperationNo, new { id = "MyId" })

@Html.TextBoxFor(item => item.OperationNo, htmlAttributes: new { id = "MyId" })

输出:

<input ... id="MyId" name="OperationNo" type="text" />

关于javascript - 如何在 MVC 上将 id 设置为 Html.TextBox 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16969262/

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