我有一个选择,有一个很长的列表,我可以在其中搜索它,使用 select2 jquery pluing。
我的选择:
@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-->
}
我需要它能够让我搜索和选择我想使用的选项。按回车键或鼠标单击。然后它提交表单...
当然,它还必须与普通的提交按钮一起使用...
我试过这段代码:
$(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();
});
关于javascript - 选择选项时jquery提交选择表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39634290/