質問するログイン新規登録

質問編集履歴

1

現在のソースコードを追記しました。

2020/05/21 05:22

投稿

tomokonkon
tomokonkon

スコア1

title CHANGED
File without changes
body CHANGED
@@ -8,5 +8,147 @@
8
8
  条件によって出すページが違うので上手く表示できない状況です。。
9
9
  何か良いソースコードの書き方を教えてください。よろしくお願いします。
10
10
 
11
+
12
+ ▼現段階のソース▼
13
+ <!doctype html>
14
+ <html lang="ja">
15
+ <head>
16
+ <meta charset="UTF-8">
17
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
18
+ <title>物件購入診断ページ</title>
19
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
20
+ <link rel="stylesheet" href="css/reset.css">
21
+ <!--リセット-->
22
+ <link rel="stylesheet" href="css/style.css">
23
+ <script type="text/javascript" src="js/jquery-3.2.0.min.js"></script>
24
+ <script type="text/javascript" src="js/modal.js"></script>
25
+ <script>
26
+ $(function(){
27
+ //ボタンがクリックされた時
28
+ $("button").click(function(){
29
+ //一度結果を非表示にする
30
+ $(".result").hide();
31
+
32
+ //問題数を取得
33
+ var qNum = $("ul li").length;
34
+
35
+ if( $("ul li input:checked").length < qNum ){
36
+ //全てチェックしていなかったらアラートを出す
37
+ alert("未回答の問題があります");
38
+ } else {
39
+ //チェックされているinputの数を取得
40
+ var typeANum = $(".typeA:checked").length,
41
+ typeBNum = $(".typeB:checked").length,
42
+ typeCNum = $(".typeC:checked").length,
43
+ typeDNum = $(".typeD:checked").length;
44
+ if( typeANum >= 4 ) {
45
+ //4個以上の場合
46
+ $(".resultA").fadeIn();
47
+ } else if( typeANum >= 2 ) {
48
+ //2~3個の場合
49
+ $(".resultB").fadeIn();
50
+ } else if( typeANum >= 0 ) {
51
+ //0~1個の場合
52
+ $(".resultC").fadeIn();
53
+ }
54
+ }
55
+ });
56
+ })
57
+ </script>
58
+ <script>
59
+ $(document).ready(function() {
60
+ $("#open").on("click", function(e) {
61
+ e.preventDefault();
62
+ $("#overlay, #modal").addClass("active");
63
+
64
+ $("#close, #overlay").on("click", function() {
65
+ $("#overlay, #modal").removeClass("active");
66
+ return false;
67
+ });
68
+ });
69
+ });
70
+ </script>
71
+ </head>
72
+
73
+ <body>
74
+ <div id="wrapper">
75
+ <div class="question">
76
+ <h1>今のあなたの状況は?</h1>
77
+ <ul>
78
+ <li> <span>Q1. 質問ここに入る</span>
79
+ <label>
80
+ <input type="radio" name="q01" class="typeA">
81
+ YES</label>
82
+ <label>
83
+ <input type="radio" name="q01" class="typeB">
84
+ NO</label>
85
+ </li>
86
+ <li> <span>Q2. 質問ここに入る</span>
87
+ <label>
88
+ <input type="radio" name="q02" class="typeA">
89
+ YES</label>
90
+ <label>
91
+ <input type="radio" name="q02" class="typeB">
92
+ NO</label>
93
+ </li>
94
+ <li> <span>Q3. 質問ここに入る</span>
95
+ <label>
96
+ <input type="radio" name="q03" class="typeA">
97
+ YES</label>
98
+ <label>
99
+ <input type="radio" name="q03" class="typeB">
100
+ NO</label>
101
+ </li>
102
+ <li> <span>Q4. 質問ここに入る</span>
103
+ <label>
104
+ <input type="radio" name="q04" class="typeA">
105
+ YES</label>
106
+ <label>
107
+ <input type="radio" name="q04" class="typeB">
108
+ NO</label>
109
+ </li>
110
+ <li> <span>Q5. 質問ここに入る</span>
111
+ <label>
112
+ <input type="radio" name="q05" class="typeA">
113
+ YES</label>
114
+ <label>
115
+ <input type="radio" name="q05" class="typeB">
116
+ NO</label>
117
+ </li>
118
+ <li> <span>Q6. 質問ここに入る</span>
119
+ <label>
120
+ <input type="radio" name="q06" class="typeA">
121
+ YES</label>
122
+ <label>
123
+ <input type="radio" name="q06" class="typeB">
124
+ NO</label>
125
+ </li>
126
+ </ul>
127
+ <button>診断する</button>
128
+ </div>
129
+ <div class="result resultA">
130
+ <h2>YESの数が4個以上<br>
131
+ </h2>
132
+ <p>答が入る</p>
133
+ <p><a href="#">セミナー申し込み</a></p>
134
+ <button id="close">CLOSE</button>
135
+ </div>
136
+ <div class="result resultB">
137
+ <h2>YESの数が2~3個<br>
138
+ </h2>
139
+ <p>答が入る</p>
140
+ <p><a href="#">セミナー申し込み</a></p>
141
+ </div>
142
+ <div class="result resultC">
143
+ <h2>YESの数が0~1個<br>
144
+ </h2>
145
+ <p>答が入る。</p>
146
+ <p><a href="#">セミナー申し込み</a></p>
147
+ </div>
148
+ </div>
149
+ </body>
150
+ </html>
151
+ // JavaScript Document
152
+
11
153
  ▼参考にしたページ▼
12
154
  https://sole-color-blog.com/blog/1060/