我有一个选择,有一个很长的列表,我可以在其中搜索它,使用 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-->
}
我需要它能够让我搜索并选择我想要使用的选项。按 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();
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)