作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我试图通过 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/
我是一名优秀的程序员,十分优秀!