【发布时间】:2016-12-21 05:30:39
【问题描述】:
如果用户在另一个选择输入下拉列表中选择了一个值,我正在尝试禁用文本输入框。基本上,他们可以从列表中选择,也可以输入一个值,不能同时输入。
我目前正在尝试这个sn-p,它似乎没有任何效果:
//If the #chooseOrg select box has a value, we disable the #enterOrg box
var chosen = $('#chooseOrg').find('select');
var enterInput = $('#enterOrg').find('input');
if (chosen.val()) {
enterInput.prop('disabled', true);
}
//On the new listings pages, for producer/org select
//Disable the text box input if the user selects an org from the list
$('#chooseOrg').find('select').on('select2-selecting', function() {
if ($(this).val()) {
enterInput.prop('disabled', true);
}
});
//Re-enable the text input if they clear their selection
$('#chooseOrg').find('select').on('select2-removed', function() {
$('#enterOrg').find('input').prop('disabled', false);
});
编辑:更新代码以获得更好的语法
请注意,我必须使用 find(':input'),因为我正在与嵌套在插件生成的代码中的字段进行交互,因此我无法为字段本身提供正确的 ID。
有人看到我错过了什么吗?
【问题讨论】:
-
我认为问题是我没有从 select2 输入中正确获取值,但我想不出正确的方法......
标签: jquery validation input