私が使用する jQuery 関数は、1 つのページで同じ選択値を選択する可能性を無効にします。例: ページ 2 に異なる選択があり、最初の選択で選択した値が 1 の場合、2 番目の選択では値 1 を無効にする必要があります。コメント付きの jQuery 関数を見つけましたが、それが機能している方法がわかりません。
var previous = -1;
// Setting a previously selected value
$("select").change(function () {
// When any select element is changed
if ($(this).val() > -1) {
// When value is > -1
// Get all selects but not the current one which triggered the change event
$("select").not(this)
.find("option[value=" + $(this).val() + "]").attr('disabled', 'disabled');
// set the current option value to disabled
// Get all selects but not the current one which triggered the change event
$("select").not(this)
.find("option[value=" + previous + "]").removeAttr('disabled');
// Remove the disabled property on previous value
} else {
// Get all selects but not the current one which triggered the change event
$("select").not(this)
.find("option[value=" + previous + "]").removeAttr('disabled');
// Remove the disabled property
}
}).focus(function () {
previous = $(this).val();
// store the current value of the select to previous
});
ここに JSFiddle リンクがあります: http://jsfiddle.net/Z2yaG/4/
誰かが私にvarの前の配列であることを説明できますか? 関数は以前の変数のすべての選択からの値をどのように保存しますか?