自己顶上去,请高手帮忙啊
源代码再发过一遍如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js操作checkbox</title>
</head>
<body>
<script language="javascript">
function savePower()
{
if (confirm("你确定要这样设置吗?")) 
{
//      var cbox=document.all.item("cbox");
var cbox=document.all.myform.cbox;//获取myform表单中所有name为cbox的复选按钮集合;
var pUrl="";
// var MyArray=new Array();
for(var i=0;i<=cbox.length;i++)
 {
//    MyArray[i]=(cbox[i].checked?1:0);
   pUrl+="url"+(i+1)+"="+(cbox[i].checked?1:0)+"&";
//        alert(pUrl);//这里alert()正常;
 }
pUrl=pUrl.substring(0,pUrl.length-2);
// alert(pUrl);在这里alert()没有任何反应
document.all.myform.action="save.asp?"+pUrl;
document.all.myform.submit();
}
else
{
    return false;
}
}
</script>
<form name="myform" method="post">
  <table width="35%" border="0" cellspacing="0" cellpadding="0"  align="center" style="border:1px solid #cccccc;">
    <tr>
      <td colspan="2" align="center" height="35"><b>用户权限设置中心</b></td>
    </tr>
    <tr>
      <td height="30" align="right">结算表权证信息:</td>
      <td> <input type='checkbox' name='cbox' value=1>是</td>
    </tr>
    <tr><td height="30" align="right">结算表客户信息:</td><td><input type='checkbox' name='cbox' value=1>是    </td>
    </tr>
    <tr>
      <td height="30" align="right">结算表财务信息:</td><td><input type='checkbox' name='cbox' value=1>是    </td>
    </tr>
    <tr>
      <td height="30" align="right">打印结算表:</td><td><input type='checkbox' name='cbox' value=1>是 </td>
    </tr>
    <tr> <td height="30" align="right">删除结算表:</td><td><input type='checkbox' name='cbox' value=1>是</td>
    </tr>
    <tr><td colspan="2" align="center" height="35"><input name="tj" type="button" value="提 交" onClick="savePower();">
      <input name="action" type="hidden" value="ok"></td></tr> </table></form>
</body>
</html>

解决方案 »

  1.   

     var cbox=document.getElementsByTagName("input");
            var pUrl="";
            for(var i=0;i<=cbox.length;i++)
             {
                    if(cbox[i].type=="checkbox")
                    pUrl+="url"+(i+1)+"="+(cbox[i].checked?1:0)+"&";
             }
      

  2.   

    首先指出你一点
    for(var i=0;i<=cbox.length;i++)
    改为for(var i=0;i<cbox.length;i++)其他的还没看
      

  3.   

    再帮你改一部分
    for(var i=0;i<cbox.length;i++)
             {
    //           MyArray[i]=(cbox[i].checked?1:0);
    var flag=cbox[i].checked==true?1:0
               if(pUrl==""){
    pUrl="url"+(i+1)+"="+flag;
    }
    else{

               pUrl+="&url"+(i+1)+"="+flag;
        
       }
    //          ;
             }
            pUrl=pUrl.substring(0,pUrl.length);
      

  4.   

    <script>
    function savePower()
    {
        if (confirm("你确定要这样设置吗?")) 
        {
    //      var cbox=document.all.item("cbox");
            var cbox=document.myform.cbox;//获取myform表单中所有name为cbox的复选按钮集合;
            var pUrl="";
    //        var MyArray=new Array();
            for(var i=0;i<cbox.length;i++)
             {
    //           MyArray[i]=(cbox[i].checked?1:0);
    var flag=cbox[i].checked==true?1:0
               if(pUrl==""){
    pUrl="url"+(i+1)+"="+flag;
    }
    else{

               pUrl+="&url"+(i+1)+"="+flag;
        
       }
    //          ;
             }
            pUrl=pUrl.substring(0,pUrl.length);
            myform.action='save.asp?'+pUrl+'';
            myform.submit;
        }
        else
        {
            return false;
        }
    }
    </script>
      

  5.   

    <script>
    function savePower()
    {
        if (confirm("你确定要这样设置吗?")) 
        {
    //      var cbox=document.all.item("cbox");
            var cbox=document.myform.cbox;//获取myform表单中所有name为cbox的复选按钮集合;
            var pUrl="";
    //        var MyArray=new Array();
            for(var i=0;i<cbox.length;i++)
             {
    //           MyArray[i]=(cbox[i].checked?1:0);
    var flag=cbox[i].checked==true?1:0
               if(pUrl==""){
    pUrl="url"+(i+1)+"="+flag;
    }
    else{

               pUrl+="&url"+(i+1)+"="+flag;
        
       }
    //          ;
             }
            pUrl=pUrl.substring(0,pUrl.length);
            document.form.action='save.asp?'+pUrl+'';
            document.form.submit();
        }
        else
        {
            return false;
        }
    }
    </script>
      

  6.   

    提交的效果还是出不来,
    在for循环外alert(pUrl)现在是可以出来了。谢谢各位啊
      

  7.   

    是不是我的Html 代码也有问题啊?
    我这里测试,真的是提交后没有反应。麻烦你把你测试的整个文件代码贴出来好吗?谢谢
      

  8.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    </head><body><script>
    function savePower()
    {
        if (confirm("你确定要这样设置吗?")) 
        {
    //      var cbox=document.all.item("cbox");
            var cbox=document.myform.cbox;//获取myform表单中所有name为cbox的复选按钮集合;
            var pUrl="";
    //        var MyArray=new Array();
            for(var i=0;i<cbox.length;i++)
             {
    //           MyArray[i]=(cbox[i].checked?1:0);
    var flag=cbox[i].checked==true?1:0
               if(pUrl==""){
    pUrl="url"+(i+1)+"="+flag;
    }
    else{

               pUrl+="&url"+(i+1)+"="+flag;
        
       }
    //          ;
             }
            pUrl=pUrl.substring(0,pUrl.length);
            document.myform.action='save.asp?'+pUrl+'';
            document.myform.submit();
        }
        else
        {
            return false;
        }
    }
    </script><form name="myform" method="post" action=""> 
      <table width="35%" border="0" cellspacing="0" cellpadding="0"  align="center" style="border:1px solid #cccccc;"> 
        <tr> 
          <td colspan="2" align="center" height="35"> <b>用户权限设置中心 </b> </td> 
        </tr> 
        <tr> 
          <td height="30" align="right">结算表权证信息: </td> 
          <td> <input type='checkbox' name='cbox' value=1>是 </td> 
        </tr> 
        <tr> <td height="30" align="right">结算表客户信息: </td> <td> <input type='checkbox' name='cbox' value=1>是    </td> 
        </tr> 
        <tr> 
          <td height="30" align="right">结算表财务信息: </td> <td> <input type='checkbox' name='cbox' value=1>是    </td> 
        </tr> 
        <tr> 
          <td height="30" align="right">打印结算表: </td> <td> <input type='checkbox' name='cbox' value=1>是 </td> 
        </tr> 
        <tr> <td height="30" align="right">删除结算表: </td> <td> <input type='checkbox' name='cbox' value=1>是 </td> 
        </tr> 
        <tr> <td colspan="2" align="center" height="35"> <input name="tj" type="button" value="提 交" onClick="savePower();"> 
          <input name="action" type="hidden" value="ok"> </td> </tr> </table> </form> </body>
    </html>
      

  9.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    </head><body><script>
    function savePower()
    {
        if (confirm("你确定要这样设置吗?")) 
        {
    //      var cbox=document.all.item("cbox");
            var cbox=document.myform.cbox;//获取myform表单中所有name为cbox的复选按钮集合;
            var pUrl="";
    //        var MyArray=new Array();
            for(var i=0;i<cbox.length;i++)
             {
    //           MyArray[i]=(cbox[i].checked?1:0);
    var flag=cbox[i].checked==true?1:0
               if(pUrl==""){
    pUrl="url"+(i+1)+"="+flag;
    }
    else{

               pUrl+="&url"+(i+1)+"="+flag;
        
       }
    //          ;
             }
            pUrl=pUrl.substring(0,pUrl.length);
            document.form.action='save.asp?'+pUrl+'';
            document.form.submit();
        }
        else
        {
            return false;
        }
    }
    </script><form name="myform" method="post" action=""> 
      <table width="35%" border="0" cellspacing="0" cellpadding="0"  align="center" style="border:1px solid #cccccc;"> 
        <tr> 
          <td colspan="2" align="center" height="35"> <b>用户权限设置中心 </b> </td> 
        </tr> 
        <tr> 
          <td height="30" align="right">结算表权证信息: </td> 
          <td> <input type='checkbox' name='cbox' value=1>是 </td> 
        </tr> 
        <tr> <td height="30" align="right">结算表客户信息: </td> <td> <input type='checkbox' name='cbox' value=1>是    </td> 
        </tr> 
        <tr> 
          <td height="30" align="right">结算表财务信息: </td> <td> <input type='checkbox' name='cbox' value=1>是    </td> 
        </tr> 
        <tr> 
          <td height="30" align="right">打印结算表: </td> <td> <input type='checkbox' name='cbox' value=1>是 </td> 
        </tr> 
        <tr> <td height="30" align="right">删除结算表: </td> <td> <input type='checkbox' name='cbox' value=1>是 </td> 
        </tr> 
        <tr> <td colspan="2" align="center" height="35"> <input name="tj" type="button" value="提 交" onClick="savePower();"> 
          <input name="action" type="hidden" value="ok"> </td> </tr> </table> </form> </body>
    </html>
      

  10.   

     <input name="action" type="hidden" value="ok">
    因为你这里有action
    所以我建议你把这个给改了
      

  11.   

    好的,谢谢你,你说的没错,去掉了<input name="action" type="hidden" value="ok">就没什么问题了,
    不过,不能用“document.form.submit();”而得用“document.myform.submit();”才会提交成功。
    另外我用ajax也解决了问题。
    非常谢谢你了,幸好你这么热心的帮助!