2016-07-27 45 views
0

嗨我想知道如何通过在MVC5中按Enter键导航从一个字段到另一个字段。如何使用MVC5中的输入键功能从一个字段导航到另一个字段

我查看

<form> 
    <fieldset> 
    <div class="col-sm-3"> 
    <div class="form-group"> 
    <span style="color: #f00">*</span> 
    @Html.Label("Employee Name", new { @class = "control-label" }) 
    @Html.DropDownList("EmployeeID", null, "Select", new { @class = "form-control required" }) 
    </div> 
    </div> 

    <div class="col-sm-3"> 
    <div class="form-group"> 
    <span style="color: #f00">*</span> 
    @Html.LabelFor(model => model.Date, new { @class = "control-label" }) 
    @Html.TextBoxFor(model => model.Date, new { @class = "form-control required", type = "text", id = "Date" }) 
    </div> 
    </div> 

    <div class="col-sm-3" style="float:left"> 
    <div class="form-group"> 
    <span style="color: #f00">*</span> 
    @Html.LabelFor(model => Model.CustomerName, new { @class = "control-label" }) 
    @Html.TextBoxFor(model => Model.CustomerName, new { @class = "form-control" }) 
    @Html.HiddenFor(model => Model.CustomerID) 
    </div> 
    </div> 

    <div class="col-sm-4" id="VisitType"> 
    <div class="form-group"> 
    <span style="color: #f00">*</span> 
    @Html.Label("Visit Type", new { @class = "control-label" }) 
    @Html.RadioButtonFor(model => model.VisitType, "true", new { id = "" }) Telephone 
    </label> 
    <label> 
    @Html.RadioButtonFor(model => model.VisitType, "false", new { id = "" }) Direct Visit 
    </label> 
    </div> 
    </div> 

    <form> 
    <fieldset> 

我Ĵ查询

$("form:not(.filter) :visible:enabled:first").focus(); 
    $('form > div').keypress(function(e) { 
    debugger; 
    if (e.keyCode == 13) { 
    e.preventDefault(); 
    if ($(this).next().length > 0) { 
    $(this).next().children('div').children(":not(label)").focus(); 
    } else { 
    $("form:not(.filter) :visible:enabled:first").focus(); 
    } 
    } 
    }); 

我的CSS

下面这段代码工作鳍片在小提琴中。但是这个代码在我的View中不起作用。为什么,因为我不知道我在哪里必须在我的视图中声明这个CSS。请任何人检查我的代码,并告诉我这个问题的建议。在我有脚本文件夹中的css文件之前。所以我在我的视图中拖动并保留该css文件。我donno并没有任何css文件的这个关键功能。所以,请任何人告诉我,我必须在我的视图中声明该css编码。任何人都建议我改变方法。我尽力解释我的问题。任何一个明白,并给我解决方案

谢谢。

+0

是它的局部视图 – lordkain

+0

不,它不是一个局部视图。这只是一个主要观点? –

回答

0

1 CSS

你的观点有这样

@{ 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}  
在_Layout.cshtml

你在文件的site.css的顶部看到一个布局属性包括在内,像这样:

@Styles.Render("~/Content/css") 
// look at App_Start/BundleConfig.cs to look up which style sheets are included 

把你的CSS放在site.css文件中。

2. JavaScript的

在视图中添加部分脚本你的JavaScript

// view code here .... 

@section scripts 
{ 
// include scripts here 
} 
+0

我添加了jQuery代码之间的部分。现在我的疑问是,我必须在视图div中添加此CSS代码{margin:5px 10px; } –

+0

你想让它算作整个网站吗? – lordkain

+0

整个站点意味着你问所有视图或所有领域,特别是视图? –

相关问题