Cod*_*ver 5 javascript forms asp.net-mvc jquery
我有一个来自.
@using (Html.BeginForm())
{
// From content
<div class="form-group btn-group">
<button type="submit" class="btnPrimaryStyle btn col-sm-3 col-xs-12 pull-left">Save</button>
</div>
}
Run Code Online (Sandbox Code Playgroud)
一切都很好.我有一个不在形式的dropdwon.我想检查一下,如果选择了下拉值,则可以提交表单,否则将不提交.简而言之,下拉选项是必需的,它不在形式之内.我可以使用jquery或javascript检查dropdwon天气的值是否被选中.我的问题是如果没有选择值,我如何阻止提交表单?
使用jQuery很简单:
$("#your-form-id").submit(function (e) { // note that it's better to use form Id to select form
if($("#YourDropDownID").val() == 0 || $("#YourDropDownID").val() == '') // here you check your drop down selected value
{
e.preventDefault(); // here you stop submitting form
}
}
Run Code Online (Sandbox Code Playgroud)
设置id为form使用此重载:
Html.BeginForm(null, null, FormMethod.Post, new { id = "your_form_id" })
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8637 次 |
| 最近记录: |