【问题标题】:Jquery submit select form when option is selected选择选项时Jquery提交选择表单
【发布时间】:2017-01-30 18:01:27
【问题描述】:

我有一个选择,有一个很长的列表,我可以在其中搜索它,使用 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();
            });
        });
    });

它在我搜索之前提交,但如果我通常滚动列表并点击它就可以工作..

【问题讨论】:

  • 不清楚你的问题到底是什么,或者你到底有什么问题。请提供minimal reproducible example 来演示问题(我们不需要您的服务器端代码)

标签: javascript c# jquery html forms


【解决方案1】:

如果您想在更改选择选项后提交表单:

$('.selectpicker').on('change', function () {
   $(this).closest('form').submit();
});

【讨论】:

  • 是的,当然......应该已经看到......它只是改变的选择......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-29
  • 2021-11-24
  • 2016-08-05
  • 1970-01-01
  • 1970-01-01
  • 2012-02-28
  • 1970-01-01
相关资源
最近更新 更多