この関数をより一般的に書くにはどうすればよいですか?だから私はこれを何度も何度も繰り返す必要はないのですか?複数の入力で同様の変更イベントハンドラを簡略化
jQuery("input[name='option1']").change(function() {
$("#option1").addClass('highlight');
setTimeout(function() {
$("#option1").removeClass("highlight");
}, 100);
});
jQuery("input[name='option2']").change(function() {
$("#option2").addClass('highlight');
setTimeout(function() {
$("#option2").removeClass("highlight");
}, 100);
});
jQuery("input[name='optionX']").change(function() {
$("#optionX").addClass('highlight');
setTimeout(function() {
$("#optionX").removeClass("highlight");
}, 100);
});
あなたは私たちが要素をDOMで互いにどのように関係するかを見ることができる質問には、あなたのHTMLを追加してくださいすることができます。 –