有一个面页,上面有[新增][修改][删除]三个按钮,还有五个复选框,但用户只能选择一个复选,当用户按了其中一个按钮后(如果是新增),并且只能选择一个复选框,然后就将复选框的值发送到要处理业务的新增页面,这个JSP的<javascript>应该怎么写啊?先谢谢了啊

解决方案 »

  1.   

    为什么用checkbox呢,用radio不是很好吗?
      

  2.   

    1.每个复选框的ID不能重复;
    2.写一个JS的FUNCTION,接收的是OBJECT,循环判断,除了接收到的OBJECT是被checked的状态,其它的均为不被选中的状态;
    3.在每个复选框上加一个ONCLICK的动作,调用第2步写的FUNCTION,就可以了。
    思路就是这样的。
      

  3.   

    一个radio的
    <script language="JavaScript" type="text/JavaScript">
    function add(){ var r_value;
     for(i=0;i<document.form1.r1.length;i++){
    if(document.form1.r1[i].checked == true){
          r_value=document.form1.r1[i].value;
    }} //alert(r_value);
    location.href="http://www.xxx.cn?id=<%r_value%>";
    }
    </script>
    <form name="form1" method="post" action="">
      <input type="button" name="Button0" value="ADD" onClick="add()">
      <input type="button" name="Button1" value="Button1">
      <input type="button" name="Button2" value="Button2">
      <input name="r1" type="radio"  value="1" checked >
      1 
      <input type="radio" name="r1" value="2">
      2 
      <input type="radio" name="r1" value="3">
      3
    </form>
      

  4.   

    <script language="JavaScript" type="text/JavaScript">
    var c_value;
    function add(){
    alert(c_value);
    location.href="http://www.baidu.cn?id=<%c_value%>";
    }
    function c_checked(o,form)
    {
         c_value=o.value;
    for (var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
    if (e.type == 'checkbox'&&e!=o)
    e.disabled = o.checked;

    }
       
    }
    </script>
    </head>
    <body>
    <form name="form1" method="post" action="">
      <input type="button" name="Button0" value="ADD" onClick="add()">
      <input type="button" name="Button1" value="Button1">
      <input type="button" name="Button2" value="Button2">
      <input type="checkbox" name="c1" value="1" onclick="c_checked(this,this.form)">
      1 
      <input type="checkbox" name="c2" value="2" onclick="c_checked(this,this.form)">
      2 
      <input type="checkbox" name="c3" value="3" onclick="c_checked(this,this.form)">
      2 
    </form>
      

  5.   

    要是必须使用复选框怎么办啊?而且不能用URL传值,是不是挺头痛的
      

  6.   

    form不是有个action吗,要动态的用按钮去改变action的发送页面,
      

  7.   

    luobo525(自渡) 
    复选框多点几下自己就变灰了?鼠标动太实现复选框不可用?这个功能不用实现啊,好像有点不太好用啊,能不能不用URL传值
      

  8.   

    晕,赚分真不容易啊<script language="JavaScript" type="text/JavaScript">
    var c_value;
    function add(){
    //############
    document.form1.act.value="add";
    //############
    }
    function c_checked(o,form)
    {
    c_value=o.value;
    for (var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
    if (e.type == 'checkbox'&&e!=o)
    e.disabled = o.checked;}}
    </script>
    <form name="form1" method="post" action="option.jsp">###########################
    <input type="hidden" value="" name="act">
    #########################<input type="button" name="Button0" value="ADD" onClick="add()">
    <input type="button" name="Button1" value="Button1">
    <input type="button" name="Button2" value="Button2">
    <input type="checkbox" name="c1" value="1" onclick="c_checked(this,this.form)">
    1
    <input type="checkbox" name="c2" value="2" onclick="c_checked(this,this.form)">
    2
    <input type="checkbox" name="c3" value="3" onclick="c_checked(this,this.form)">
    2
    </form>在option.jsp中,先得到act,看看是什么按钮过来的