我有一个输入字段(源语言),当我单击其中一种源语言时,具有相同文本的目标语言被禁用
到目前为止我已经做到了,但是当我单击源语言时它仍然禁用目标语言
我想每次重置它..而不是总是监听事件
这是演示 http://jsfiddle.net/ezNxU/
// change the target language according to the source language
$('#source').change(function () {
var option_source = $('select#source option:selected').text();
$('select#target option').each(function () {
if ($(this).text() == option_source) $(this).prop("disabled", true);
console.log($(this).text());
});
});
最佳答案
要重置禁用属性,请将其应用于所有选项,并使用函数调用将其设置为 true/false
$('#source').on('change', function() {
var self = this;
$('#target option').prop('disabled', function() {
return this.value == self.value;
});
});
关于jquery - 选择相同输入时禁用输入字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15659590/