特定のスクリプトがビューに存在する場合、ヘルパー/拡張メソッドをチェックインする方法はありますか?
私の考えは、現在の入力が maxLenght に達するとフォーカスが次の入力に移動するカスタム TextBoxFor() メソッドを作成することです。
特定のスクリプトがビューに存在する場合、ヘルパー/拡張メソッドをチェックインする方法はありますか?
私の考えは、現在の入力が maxLenght に達するとフォーカスが次の入力に移動するカスタム TextBoxFor() メソッドを作成することです。
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>
これで、必要に応じて autotab 機能を利用できるようになります。
このタスクに JavaScript を使用しないのはなぜですか?
例: http://www.aspdotnet-suresh.com/2013/02/javascript-automatically-move-cursor-to.html