<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www./1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JQuery radio</title> <script type="text/javascript" language="javascript" src="JavaScript/jquery-1.6.1.min.js" ></script> <script type="text/javascript" language="javascript"> /*------判斷radio是否有選中,獲取選中的值--------*/ $(function(){ $("#btnSubmit").click(function(){ var val=$('input:radio[name="sex"]:checked').val(); if(val==null){ alert("什么也沒選中!"); return false; } else{ alert(val); } var list= $('input:radio[name="list"]:checked').val(); if(list==null){ alert("請(qǐng)選中一個(gè)!"); return false; } else{ alert(list); } }); }); </script> </head> <body> <form id="form1" > <input type="radio" name="sex" value="男" />男 <input type="radio" name="sex" value="女" />女 <br /> <input type="radio" name="list" value="十分滿意" />十分滿意 <input type="radio" name="list" value="滿意" />滿意 <input type="radio" name="list" value="不滿意" />不滿意 <input type="radio" name="list" value="非常差" />非常差 <br /> <input type="submit" value="submit" id="btnSubmit" /> </form> </body> </html> |
|