我试图禁用文本输入框,如果用户在另一个选择输入下拉列表中选择一个值。基本上,他们可以从列表中选择,或者输入一个值,而不是两个值。当用户选择选项时禁用文本输入
我目前想这个片段中,这似乎并没有遇到的任何影响:
//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);
});
编辑:为更好的语法
请注意,我必须使用查找(”更新代码:input'),因为我与嵌套在由插件生成的代码中的字段进行交互,所以我不能给这些字段本身提供正确的ID。
有人看到我失踪了吗?
我认为这个问题是我没有从选择2输入正确获取值,但我无法找出正确的方式.... – Eckstein