自己顶上去,请高手帮忙啊
源代码再发过一遍如下:
<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>
源代码再发过一遍如下:
<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>
var pUrl="";
for(var i=0;i<=cbox.length;i++)
{
if(cbox[i].type=="checkbox")
pUrl+="url"+(i+1)+"="+(cbox[i].checked?1:0)+"&";
}
for(var i=0;i<=cbox.length;i++)
改为for(var i=0;i<cbox.length;i++)其他的还没看
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);
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>
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>
在for循环外alert(pUrl)现在是可以出来了。谢谢各位啊
我这里测试,真的是提交后没有反应。麻烦你把你测试的整个文件代码贴出来好吗?谢谢
<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>
<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>
因为你这里有action
所以我建议你把这个给改了
不过,不能用“document.form.submit();”而得用“document.myform.submit();”才会提交成功。
另外我用ajax也解决了问题。
非常谢谢你了,幸好你这么热心的帮助!