[英]Jquery submit select form when option is selected
我有一个选择,有很长的列表,我可以用select2 jquery插入来搜索它。
我的选择:
@using (Html.BeginForm("ProjectList", "Client", FormMethod.Get, new { id = "clientform", name = "clientoverviewform"}))
{
<div class="form-group">
<label for="sel1">Select Client</label>
@if (Model.ClientList != null)
{
<select class="form-control selectpicker" data-live-search="true" id="sel1" name="id">
@foreach (var client in Model.ClientList)
{
<option value="@client.Id">@client.Name</option>
}
</select>
}
</div><!-- end form-group-->
<div class="form-group">
<input type="submit" value="Vis" class="form-control">
</div><!-- end form-group-->
}
我需要它能够让我搜索并选择我要使用的选项。 按Enter或单击鼠标。 然后提交表格
当然,它也必须使用正常的提交按钮
我试过这段代码:
$(document).ready(function () {
$('#clientform').on('change', function () {
var $form = $(this).closest('form').on('change', function () {
$form.find('input[type=submit]').click();
});
});
});
即使我只是在列表中滚动并单击,它也可以在搜索之前提交。
如果要在更改选择选项后提交表单,请执行以下操作:
$('.selectpicker').on('change', function () {
$(this).closest('form').submit();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.