1

ソース言語の1つをクリックしたときに必要な入力フィールド(ソース言語)があり、同じテキストのターゲット言語が無効になっています

私はこれまでにそれを行いましたが、ソース言語をクリックするとターゲット言語が無効になり続けます

毎回リセットしたいもの..常にイベントを聞かせないようにする

これがデモです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());
});

});
4

4 に答える 4

2

無効なプロパティをリセットするには、すべてのオプションに適用し、関数呼び出しを使用してtrue/falseに設定します

$('#source').on('change', function() {
    var self = this;
    $('#target option').prop('disabled', function() {
        return this.value == self.value;
    });
});

フィドル

于 2013-03-27T13:13:34.870 に答える
1

これを試して:

$('#source').change(function () {
    var option_source = $('select#source option:selected').text();
    $('select#target option').each(function () {
        $(this).prop("disabled", ($(this).text() == option_source));
    });
});

デモ

于 2013-03-27T13:10:57.000 に答える
0

これを使用してすべてをクリアします

$('select#target option').prop("disabled",false); 

だからあなたのコードのために:フィドル

 $('#source').change(function () {

            var option_source = $('select#source option:selected').text();
                $('select#target option').prop("disabled",false);
            $('select#target option').each(function () {

                if ($(this).text() == option_source) $(this).prop("disabled", true);
                console.log($(this).text());
            });
        });
于 2013-03-27T13:11:36.590 に答える
0

変更イベントで無効化プロパティを削除するだけです...これにより、すべてのオプションから無効化が削除され、後でコードが追加されます...

これを試して

 $('#source').change(function () {
   $('select#target option').prop("disabled", false); //<-- add this line
   .....

ここをいじる

于 2013-03-27T13:11:58.317 に答える