(function ($) { $(document).ready(function () { radioSelectAction(); }); var Control = { scrollCount: 0, scrollCount2: 0, answer: { q1: '', q2: '', q3: '' }, answer1: '', answer2: '', resetAll: function () { $('#content_right').find('input[type="radio"]').prop('checked', false); this.reset1(); }, reset1: function () { $('#support_set01').find('input[type="radio"]').prop('checked', false); this.reset2(); }, reset2: function () { this.scrollCount2 = 0; $('.support_bg02').find('input[type="radio"]').prop('checked', false); $('.step2_content').hide(); this.reset3(); }, reset3: function () { $('.step3_content').hide(); }, setAnswer: function () { $('input[name="support_btn01"]:checked').length > 0 ? this.answer.q1 = $('input[name="support_btn01"]:checked').prop('id') : this.answer.q1 = ""; $('input[name="support_btn02"]:checked').length > 0 ? this.answer.q2 = $('input[name="support_btn02"]:checked').prop('id') : this.answer.q2 = ""; $('input[name="support_btn03"]:checked').length > 0 ? this.answer.q3 = $('input[name="support_btn03"]:checked').prop('id') : this.answer.q3 = ""; console.log('answer=' + this.answer); this.checkAns1(); }, checkAns1: function () { if (this.answer.q1 && this.answer.q2 && this.answer.q3) { this.openStep2(); console.log('openStep2'); } else { this.reset2(); } }, openStep2: function () { var result; var posX = $('#scroll_point2').offset().top; //substr:指定した位置から、指定された文字数分の文字列を抜き出して返します。str.substr(start[, length]) var a1 = parseInt(this.answer.q1.substr(-2)); var a2 = parseInt(this.answer.q2.substr(-2)); var a3 = parseInt(this.answer.q3.substr(-2)); console.log(this.answer.q1); console.log(this.answer.q2); console.log(this.answer.q3); console.log('a1=' + a1); console.log('a2=' + a2); console.log('a3=' + a3); //条件分岐Switch文 switch (a1) { case 1: switch (a2) { case 1: switch (a3) { case 1: result = 'A'; break; case 2: result = 'B'; break; } break; case 2: switch (a3) { case 1: result = 'C'; break; case 2: result = 'D'; break; } break; } break; case 2: switch (a2) { case 1: switch (a3) { case 1: result = 'E'; break case 2: result = 'F'; break } break; case 2: switch (a3) { case 1: result = 'G'; break; case 2: result = 'H'; break; } break; } break; } this.answer1 = result; console.log('answer1=' + this.answer1); this.reset2(); var t = this.answer1.substr(0, 1); console.log('t=' + t); if (result.length > 1) { $('#support_set02' + t).addClass('plus'); } $('#support_set02' + t).show(); if (this.scrollCount < 1) { $('html,body').animate({ scrollTop: posX }); this.scrollCount = 1; } } } function radioSelectAction() { Control.resetAll(); $('#support_set01').find('input[type="radio"]').on('change', function (e) { var target = $(e.target); console.log('target=' + target); Control.setAnswer(); }); $('.step2_content').find('input[type="radio"]').on('change', function (e) { var target = $(e.target); $('.step2_content').find('input[type="radio"]').not(target).prop('checked', false); Control.setAnswer2(target); }); } })(jQuery);