0

如果视图中存在某个脚本,是否有办法签入帮助程序/扩展方法?

我的想法是创建一个自定义 TextBoxFor() 方法,一旦当前输入达到 maxLenght,焦点就会移动到下一个输入。

4

2 回答 2

1

你有 JQuery AutoTab 插件 - http://autotab.mathachew.com/

下载 AutoTab Min JS - https://github.com/Mathachew/jquery-autotab/blob/master/js/jquery.autotab.min.js

假设我有一个模型 -

public class Details
{
    public string Name { get; set; }
    public string Email { get; set; }
}

现在创建一个视图 -

@model YourNameSpave.Details

@{
    ViewBag.Title = "GetData";
}

<h2>GetData</h2>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Details</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Name, new { @class = "alphanumeric", maxlength = 10})
            @Html.ValidationMessageFor(model => model.Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Email,  new { @class = "alphanumeric", maxlength = 10})
            @Html.ValidationMessageFor(model => model.Email)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.autotab.min.js"></script>

<script>
    $(function () {
        $('.alphanumeric').autotab();
    });
</script>

现在您将获得如您所愿的自动选项卡功能。

在此处输入图像描述

于 2014-10-06T09:53:00.133 回答
1

你为什么不直接使用 javascript 来完成这个任务呢?

示例: http ://www.aspdotnet-suresh.com/2013/02/javascript-automatically-move-cursor-to.html

于 2014-10-06T08:49:10.957 回答