如何在mvc3剃刀视图中进行自动对焦 [英] how to do autofocus in mvc3 razor view

查看:106
本文介绍了如何在mvc3剃刀视图中进行自动对焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想在我的视图页面中进行自动对焦.我尝试了以下代码,但它使标签而不是文本框对焦

Hi am trying to do autofocus in my view page.I tried the below coding but it focusing the label not Textbox

<div class="contact_form">
    <div class="contact_form1">
    @Html.LabelFor(model => model.Prefix)
    </div>
    @Html.TextBoxFor(model => model.Prefix, new { autofocus = "autofocus",
    @class = "name_form" })
    @Html.ValidationMessageFor(model => model.Prefix)
    </div>


任何人都可以帮助我摆脱这个问题


any one please help me to get out of this problem

推荐答案

检查以下SO链接:

http://stackoverflow.com/questions/2998247/asp-net- mvc-html-textbox-set-autofocus-property [ ^ ]

否则,如果您使用的是jQuery,则可以轻松完成操作,

Check the following SO link:

http://stackoverflow.com/questions/2998247/asp-net-mvc-html-textbox-set-autofocus-property[^]

Else, in case you are using jQuery, you could simply do,


(' .name_form' span>).focus();
('.name_form').focus();



希望这会有所帮助!



Hope this helps!


这篇关于如何在mvc3剃刀视图中进行自动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆