日期:2014-05-16 浏览次数:20340 次
<form action="http://www.csdn.net" onsubmit=" return checkall();" > <div class="subject"> <h2>你喜欢吃的水果?</h2> <input type="radio" name="fruit" value="苹果" id="Radio1" /><label for="Radio1">苹果</label> <input type="radio" name="fruit" value="香蕉" id="Radio2" /><label for="Radio2">香蕉</label> <input type="radio" name="fruit" value="桔子" id="Radio3" /><label for="Radio3">桔子</label> <input type="radio" name="fruit" value="梨" id="Radio4" /><label for="Radio3">梨</label> </div> <div class="subject"> <h2>你喜欢的颜色?</h2> <input type="radio" name="color" value="红" id="Radio5" /><label for="Radio5">红</label> <input type="radio" name="color" value="蓝" id="Radio6" /><label for="Radio6">蓝</label> <input type="radio" name="color" value="绿" id="Radio7" /><label for="Radio7">绿</label> <input type="radio" name="color" value="紫" id="Radio8" /><label for="Radio8">紫</label> </div> <div class="subject"> <h2>你想去旅游的国家?</h2> <input type="radio" name="state" value="日本" id="Radio9" /><label for="Radio9">日本</label> <input type="radio" name="state" value="美国" id="Radio10" /><label for="Radio10">美国</label> <input type="radio" name="state" value="德国" id="Radio11" /><label for="Radio11">德国</label> <input type="radio" name="state" value="英国" id="Radio12" /><label for="Radio12">英国</label> </div> <input type="submit" value="提交" /> </form> <script type="text/javascript" > function checkall() { var divs = document.getElementsByTagName("DIV"); var ischeckall = true,ischeckone=false; for (var i = 0; i < divs.length; i++) { if (divs[i].className == "subject") { var radios = divs[i].getElementsByTagName("input"); ischeckone = false; for (var j = 0; j < radios.length; j++) { if (radios[j].checked) { ischeckone = true; break; } } if (!ischeckone) { alert("您这一题