DOM_調查問卷效果2
阿新 • • 發佈:2017-07-10
bsp amp while open none code .get else 老鼠
<html> <head> <style type="text/css"> ul{ list-style:none; margin:0px; } .close{ display:none; } .open{ display:block; } </style> </head> <scripttype="text/javascript"> function showResult(){ var number=0; var sum=0; while(number!=5){ var flag=false; var oradioNodes = document.getElementsByName("name"+(number++)); for(var x =0;x<oradioNodes.length;x++){ if(oradioNodes[x].checked){ sum=parseInt(oradioNodes[x].value)+sum; flag=true; break; } } if(!flag){ document.getElementById("result").className="open"; } }
if(sum>0){ alert(sum+"分"); } if(sum>=5 && sum<=15){ document.getElementById("result_1").className="open"; document.getElementById("result_2").className="close"; document.getElementById("result").className="close"; }else if(sum>=16){ document.getElementById("result_2").className="open"; document.getElementById("result_1").className="close"; document.getElementById("result").className="close"; } } </script> <body> <div><h1>命運預言大師</h1></div> <div id="t_1"> <h3>第一題</h3> <span>您喜歡的顏色是?</span> <ul> <li><input type="radio" value="1" name="name0" />紅色</li> <li><input type="radio" value="2" name="name0" />黃色</li> <li><input type="radio" value="3" name="name0" />藍色</li> <li><input type="radio" value="4" name="name0" />黑色</li> <li><input type="radio" value="5" name="name0" />白色</li> </ul> </div> <div id="t_2"> <h3>第二題</h3> <span>您喜歡的運動是?</span> <ul> <li><input type="radio" value="1" name="name1" />籃球</li> <li><input type="radio" value="2" name="name1" />足球</li> <li><input type="radio" value="3" name="name1"/>乒乓球</li> <li><input type="radio" value="4" name="name1" />羽毛球</li> <li><input type="radio" value="5" name="name1" />長跑</li> </ul> </div> <div id="t_2"> <h3>第三題</h3> <span>您喜歡的風景是?</span> <ul> <li><input type="radio" value="1" name="name2" />大海</li> <li><input type="radio" value="2" name="name2" />山水</li> <li><input type="radio" value="3" name="name2"/>荒漠</li> <li><input type="radio" value="4" name="name2" />草原</li> <li><input type="radio" value="5" name="name2" />其他</li> </ul> </div> <div id="t_2"> <h3>第四題</h3> <span>您喜歡的數字是?</span> <ul> <li><input type="radio" value="1" name="name3" />1-3</li> <li><input type="radio" value="2" name="name3" />4-6</li> <li><input type="radio" value="3" name="name3"/>7-9</li> <li><input type="radio" value="4" name="name3" />10</li> <li><input type="radio" value="5" name="name3" />其他</li> </ul> </div> <div id="t_2"> <h3>第五題</h3> <span>您喜歡的動物是?</span> <ul> <li><input type="radio" value="1" name="name4" />狗</li> <li><input type="radio" value="2" name="name4" />貓</li> <li><input type="radio" value="3" name="name4"/>老鼠</li> <li><input type="radio" value="4" name="name4" />老虎</li> <li><input type="radio" value="5" name="name4" />其他</li> </ul> </div> <div> <input type="button" value="查看測試結果" onclick="showResult()"/> <div id="result" class="close">請先選擇答案!</div> <div id="result_1" class="close">矮戳窮</div> <div id="result_2" class="close">高富帥</div> </div> </body> </html>
DOM_調查問卷效果2