如何在MVC3中的以下Razor代码的页面加载上设置“Amount”文本框的焦点?
<tr> <th> <div class="editor-label"> @Html.LabelFor(model => model.Amount) </div> </th> <td> <div class="editor-field"> @Html.EditorFor(model => model.Amount) @Html.ValidationMessageFor(model => model.Amount) </div> </td> </tr>
解决方法
您可以为包含div提供一个附加类:
<div class="editor-field focus"> @Html.EditorFor(model => model.Amount) @Html.ValidationMessageFor(model => model.Amount) </div>
然后你可以使用一个jQuery类选择器:
$(function() { $('.focus :input').focus(); });
这就是说,你似乎在表中有多个Amount texBoxes,显然只有一个可以有一个时间的焦点。所以假设你想要这是第一个,你可以这样做:
$('.focus :input:first').focus();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。