選択の値を基準として一部のフィールドを表示または非表示にしたいとします。フィールドを表示したり隠したりするためにループを再び印刷することを繰り返す必要はありません。同じループコードを使用して表示または非表示にしたい最善のアプローチは何ですか?JQuery - フィールドグループの表示/非表示
hideFields = function() {
var fields = $(['#foo', '#bar', '#lorem', '#ipsum'])
showHide = function (action) {
if (action === 'show' || action === 'hide') {
action = action + '();';
fields.each(function (index, value) {
$(value).parent()
.parent()
.action(); // call show||hide here... not working...
});
}
};
if ($('#select').val() === 'something') {
showHide('hide');
}
else {
showHide('show');
}
};
hideFields();
ありがとうございます。