当 bootstrap-modal 弹出表单显示时,将所选项目重置为查询选择列表中的默认值
Reset selected item to default on a query-Chosen list when bootstrap-modal popup form shows
如何在模态弹出窗体的下拉列表中重置所选项目?
编辑:
我也在用
https://github.com/harvesthq/chosen
管理列表
这不起作用:
<div class="col-lg-9">
<select class="form-control input-sm" id="branch1">
<option value="2185529A">Complaint</option>
<option value="2385529A">Request</option>
<option value="2585529A">Enquiry</option>
</select>
</div>
<!-- scripts -->
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-modal.js"></script>
<script src="js/bootstrap-modalmanager.js"></script>
$('#frmCase').on('show', function () {
$.clearFormFields(this)
$('#branch1').get(0).selectedIndex = 1;
$('#branch2').get(0).selectedIndex = 1;
});
使用事件 shown.bs.modal
处理程序:
$('#yourModalIdOrSelector').on('shown.bs.modal', function (e) {
// 1 - select second option, set to 0 for first option
$('#branch1').get(0).selectedIndex = 1;
$('#branch2').get(0).selectedIndex = 1;
});
当模态对用户可见时触发此事件。否则使用 show.bs.modal
。将其与您的代码相匹配。
由于 @norlihazmey-ghazali 对 Chosen
的评论,我最终找到了解决方案
$('#frmCase').on('shown', function (e) {
$.clearFormFields(this)
$('#branch1').get(0).selectedIndex = 0;
$('#branch2').get(0).selectedIndex = 0;
$('#branch1').trigger('chosen:updated');
$('#branch2').trigger('chosen:updated');
});
如何在模态弹出窗体的下拉列表中重置所选项目?
编辑: 我也在用 https://github.com/harvesthq/chosen
管理列表
这不起作用:
<div class="col-lg-9">
<select class="form-control input-sm" id="branch1">
<option value="2185529A">Complaint</option>
<option value="2385529A">Request</option>
<option value="2585529A">Enquiry</option>
</select>
</div>
<!-- scripts -->
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-modal.js"></script>
<script src="js/bootstrap-modalmanager.js"></script>
$('#frmCase').on('show', function () {
$.clearFormFields(this)
$('#branch1').get(0).selectedIndex = 1;
$('#branch2').get(0).selectedIndex = 1;
});
使用事件 shown.bs.modal
处理程序:
$('#yourModalIdOrSelector').on('shown.bs.modal', function (e) {
// 1 - select second option, set to 0 for first option
$('#branch1').get(0).selectedIndex = 1;
$('#branch2').get(0).selectedIndex = 1;
});
当模态对用户可见时触发此事件。否则使用 show.bs.modal
。将其与您的代码相匹配。
由于 @norlihazmey-ghazali 对 Chosen
的评论,我最终找到了解决方案 $('#frmCase').on('shown', function (e) {
$.clearFormFields(this)
$('#branch1').get(0).selectedIndex = 0;
$('#branch2').get(0).selectedIndex = 0;
$('#branch1').trigger('chosen:updated');
$('#branch2').trigger('chosen:updated');
});