我写了个JSP的  单选按钮是循环的!  是因为数据库里面有几条数据就会有几个单选按钮,但是单选的按钮的name属性的名字都是一样的!  我现在是想没有选中就alert('请选择');  但是虽然会弹,但是每次都要循环完,没一个按钮都会弹一次,
      但是我选中了之后,  也会弹框出来, 我想如果选中了就不弹了,没有选中就弹一次! 
          请高手来赐教小弟  谢谢帮忙!

解决方案 »

  1.   

    用全局变量是吧   我是javaScript验证的啊!
      

  2.   

    <%@ page language="java" import="java.util.*,entity.*,Poll.Dao.*" pageEncoding="GBK"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>  
        <title>语言统计</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">    <style type="text/css">
    <!--
    .STYLE1 {font-size: 18px}
    -->
        </style>
    <script language="javascript">
      function check(){
        var radios=document.getElementsByName("rdotype");
               for(var i=0;i<radios.length;i++)
              {
      if(radios[i].checked==true){
      return true;
      }else
                if(radios[i].checked==false)
                {   
                  alert("请选择");
      break;          
    }

             }
      }
    </script>
    </head>
      
      <body>
      <form name="form1" method="post" action="" onSubmit="return check()">
        <table width="1018" height="175" border="1">
          <tr>
            <td height="37" colspan="3"><div align="center" class="STYLE1">你最熟悉的语言是什么?</div></td>
          </tr>
          <tr>
            <td width="258">选择</td>
            <td width="386">语言</td>
            <td width="352">票数</td>
          </tr>
          <%PollDao pollDao=new PollDao();
            List list=pollDao.getAllPoll();
            for(int i=0;i<list.size();i++){
            Poll p=(Poll)list.get(i);
           %>
          <tr>
            <td height="38">
              <input type="radio" name="rdotype" value="<%=p.getId() %>">
            </td>
            <td><%=p.getPollName() %></td>
            <td><%=p.getPollCount() %></td>
          </tr>
          <%} %>
          <tr>
            <td height="46" colspan="3"><label>
              <div align="center">
                <input type="submit" name="Submit" value="提交">
                </div>
            </label></td>
          </tr>
        </table>
      </form>
      <br>
      </body>
    </html>看看吧!
      

  3.   


    <script language="javascript">
    function check(){
        var radios=document.getElementsByName("rdotype");
        var flag = false;
        for(var i=0;i<radios.length;i++){
            if(radios[i].checked==true){
                flag = true;
            }
        }
        if(!flag){   
                alert("请选择"); 
        }
    }
    </script>你看下 是这意思不 。