一个脚本的小问题
var type_dim_id= "-1 ";
var type_id= "-1 ";
var dimObj=document.all.type_dim_id;
for(var i=0;i <dimObj.length;i++){
if(dimObj[i].checked){
var inputs =document.getElementsByTagName( "input ");
var obj;
var radioName;
for(var j=0;j <inputs.length;j++)
{
if(inputs[j].type== "radio "){
obj = inputs[j];
radioName = obj.name;
if(obj.checked){
if(radioName.substring(4,radioName.length)==type_dim_id){
type_id=obj.value;
alert(type_id);
type_dim_id=dimObj[i].value;
alert(type_dim_id);
}
}
}
}
}
}
alert( "type_id= "+type_id);
alert( "type_dim_id= "+type_dim_id);
我在循环里alert可以有数据 可一到循环外面就是-1,这两个变量都是全局的郁闷
------解决方案--------------------我这么写怎么没问题啊,是别的地方的错儿吧.
------解决方案--------------------if(radioName.substring(4,radioName.length)==type_dim_id)
这个条件看着有问题.你radioName的名字里会有-1吗?
------解决方案-------------------- <html>
<head>
<title> </title>
</head>
<body>
<input name= "type_dim_id " type= "checkbox " id= "type_dim_id " value= "checkbox ">
<input name= "type_dim_id " type= "checkbox " id= "type_dim_id " value= "checkbox ">
<input name= "type_dim_id " type= "checkbox " id= "type_dim_id " value= "checkbox " checked>
<input name= "textfield " type= "text " size= "4 " maxlength= "4 ">
<input name= "textfield2 " type= "text " size= "4 " maxlength= "4 ">
<input name= "abcd-1 " type= "radio " value= "顶你个肺 " checked>
<input type= "radio " name= "cdef-1 " value= "radiobutton ">
<input type= "radio " name= "hijk-1 " value= "radiobutton ">
</body>
<script language= "javascript ">
var type_dim_id= "-1 ";
var type_id= "-1 ";
var dimObj=document.all.type_dim_id;
for(var i=0;i <dimObj.leng