jQuery とその仕組みについてもう少し理解しようとしています。 私の最後の質問ユーザー Zachary Kniebel は、「RADIO」フォームに基づいていくつかの値を表示/非表示にする方法を理解するのを手伝ってくれました。今、私は彼のコードを変更し、ループを使用してさらに改善したいと思います (おそらく彼が提案したように FOR ループ)私に)。実際には運がなかったので、ここに私の質問があります:
**
HTML は wordpress Option フレームワークによって自動的に生成されるため、変更できないことを忘れていました...
**
HTML部分を変更せずに、この関数にLOOPを使用するにはどうすればよいですか?
ここの jsfiddle 愛好家にとっては、非常に長い js CODE を使用した実際の例です。
JS
--
jQuery(document).ready(function ($) {
$types = $('.of-radio');
$types.change(function () {
$this = $(this).val();
if ($this == "0") {
/* zone 1 */
$('#section-custom_posts_name_s_n1').hide();
$('#section-custom_posts_name_p_n1').hide();
$('#section-custom_posts_name_i_n1').hide();
$('#section-custom_posts_name_d_n1').hide();
/* end zone 1 start zone 2*/
$('#section-custom_posts_name_s_n2').hide();
$('#section-custom_posts_name_p_n2').hide();
$('#section-custom_posts_name_i_n2').hide();
$('#section-custom_posts_name_d_n2').hide();
/* end zone 2 start zone 3 */
$('#section-custom_posts_name_s_n3').hide();
$('#section-custom_posts_name_p_n3').hide();
$('#section-custom_posts_name_i_n3').hide();
$('#section-custom_posts_name_d_n3').hide();
/* end zone 3 start zone 4 */
$('#section-custom_posts_name_s_n4').hide();
$('#section-custom_posts_name_p_n4').hide();
$('#section-custom_posts_name_i_n4').hide();
$('#section-custom_posts_name_d_n4').hide();
/* end zone 4 start zone 5 */
$('#section-custom_posts_name_s_n5').hide();
$('#section-custom_posts_name_p_n5').hide();
$('#section-custom_posts_name_i_n5').hide();
$('#section-custom_posts_name_d_n5').hide();
/* end zone 5 */
} else if ($this == "1") {
/* start zone 1 */
$('#section-custom_posts_name_s_n1').show();
$('#section-custom_posts_name_p_n1').show();
$('#section-custom_posts_name_i_n1').show();
$('#section-custom_posts_name_d_n1').show();
/* end zone 1 start zone 2 */
$('#section-custom_posts_name_s_n2').hide();
$('#section-custom_posts_name_p_n2').hide();
$('#section-custom_posts_name_i_n2').hide();
$('#section-custom_posts_name_d_n2').hide();
/* end zone 2 start zone 3 */
$('#section-custom_posts_name_s_n3').hide();
$('#section-custom_posts_name_p_n3').hide();
$('#section-custom_posts_name_i_n3').hide();
$('#section-custom_posts_name_d_n3').hide();
/* end zone 3 start zone 4 */
$('#section-custom_posts_name_s_n4').hide();
$('#section-custom_posts_name_p_n4').hide();
$('#section-custom_posts_name_i_n4').hide();
$('#section-custom_posts_name_d_n4').hide();
/* end zone 4 start zone 5 */
$('#section-custom_posts_name_s_n5').hide();
$('#section-custom_posts_name_p_n5').hide();
$('#section-custom_posts_name_i_n5').hide();
$('#section-custom_posts_name_d_n5').hide();
/* end zone 5 */
} else if ($this == "2") {
/* start zone 1 */
$('#section-custom_posts_name_s_n1').show();
$('#section-custom_posts_name_p_n1').show();
$('#section-custom_posts_name_i_n1').show();
$('#section-custom_posts_name_d_n1').show();
/* end zone 1 start zone 2 */
$('#section-custom_posts_name_s_n2').show();
$('#section-custom_posts_name_p_n2').show();
$('#section-custom_posts_name_i_n2').show();
$('#section-custom_posts_name_d_n2').show();
/* end zone 2 start zone 3 */
$('#section-custom_posts_name_s_n3').hide();
$('#section-custom_posts_name_p_n3').hide();
$('#section-custom_posts_name_i_n3').hide();
$('#section-custom_posts_name_d_n3').hide();
/* end zone 3 start zone 4 */
$('#section-custom_posts_name_s_n4').hide();
$('#section-custom_posts_name_p_n4').hide();
$('#section-custom_posts_name_i_n4').hide();
$('#section-custom_posts_name_d_n4').hide();
/* end zone 4 start zone 5 */
$('#section-custom_posts_name_s_n5').hide();
$('#section-custom_posts_name_p_n5').hide();
$('#section-custom_posts_name_i_n5').hide();
$('#section-custom_posts_name_d_n4').hide();
/* end zone 5 */
} else if ($this == "3") {
/*start zone 1 */
$('#section-custom_posts_name_s_n1').show();
$('#section-custom_posts_name_p_n1').show();
$('#section-custom_posts_name_i_n1').show();
$('#section-custom_posts_name_d_n1').show();
/* end zone 1 start zone 2 */
$('#section-custom_posts_name_s_n2').show();
$('#section-custom_posts_name_p_n2').show();
$('#section-custom_posts_name_i_n2').show();
$('#section-custom_posts_name_d_n2').show();
/* end zone 2 start zone 3 */
$('#section-custom_posts_name_s_n3').show();
$('#section-custom_posts_name_p_n3').show();
$('#section-custom_posts_name_i_n3').show();
$('#section-custom_posts_name_d_n3').show();
/* end zone 3 start zone 4 */
$('#section-custom_posts_name_s_n4').hide();
$('#section-custom_posts_name_p_n4').hide();
$('#section-custom_posts_name_i_n4').hide();
$('#section-custom_posts_name_d_n4').hide();
/* end zone 4 start zone 5 */
$('#section-custom_posts_name_s_n5').hide();
$('#section-custom_posts_name_p_n5').hide();
$('#section-custom_posts_name_i_n5').hide();
$('#section-custom_posts_name_d_n5').hide();
/* end zone 5 */
} else if ($this == "4") {
/* start zone 1 */
$('#section-custom_posts_name_s_n1').show();
$('#section-custom_posts_name_p_n1').show();
$('#section-custom_posts_name_i_n1').show();
$('#section-custom_posts_name_d_n1').show();
/* end zone 1 start zone 2 */
$('#section-custom_posts_name_s_n2').show();
$('#section-custom_posts_name_p_n2').show();
$('#section-custom_posts_name_i_n2').show();
$('#section-custom_posts_name_d_n2').show();
/* end zone 2 start zone 3 */
$('#section-custom_posts_name_s_n3').show();
$('#section-custom_posts_name_p_n3').show();
$('#section-custom_posts_name_i_n3').show();
$('#section-custom_posts_name_d_n3').show();
/* end zone 3 start zone 4 */
$('#section-custom_posts_name_s_n4').show();
$('#section-custom_posts_name_p_n4').show();
$('#section-custom_posts_name_i_n4').show();
$('#section-custom_posts_name_d_n4').show();
/* end zone 4 start zone 5 */
$('#section-custom_posts_name_s_n5').hide();
$('#section-custom_posts_name_p_n5').hide();
$('#section-custom_posts_name_i_n5').hide();
$('#section-custom_posts_name_d_n5').hide();
/* end zone 5 */
} else if ($this == "5") {
/* start zone 1 */
$('#section-custom_posts_name_s_n1').show();
$('#section-custom_posts_name_p_n1').show();
$('#section-custom_posts_name_i_n1').show();
$('#section-custom_posts_name_d_n1').show();
/* end zone 1 start zone 2 */
$('#section-custom_posts_name_s_n2').show();
$('#section-custom_posts_name_p_n2').show();
$('#section-custom_posts_name_i_n2').show();
$('#section-custom_posts_name_d_n2').show();
/* end zone 2 start zone 3 */
$('#section-custom_posts_name_s_n3').show();
$('#section-custom_posts_name_p_n3').show();
$('#section-custom_posts_name_i_n3').show();
$('#section-custom_posts_name_d_n3').show();
/* end zone 3 start zone 4 */
$('#section-custom_posts_name_s_n4').show();
$('#section-custom_posts_name_p_n4').show();
$('#section-custom_posts_name_i_n4').show();
$('#section-custom_posts_name_d_n4').show();
/* end zone 4 start zone 5 */
$('#section-custom_posts_name_s_n5').show();
$('#section-custom_posts_name_p_n5').show();
$('#section-custom_posts_name_i_n5').show();
$('#section-custom_posts_name_d_n5').show();
/* end zone 5 */
}
});
});