完成foo()函数的内容,要求能够弹出对话框提示当前选中的是第几个单选框

<html> 

<head>  

</head>

<body>

<form  name ="form1"  onsubmit ="return foo();">

<input  type ="radio"  name ="radioGroup"/>

<input  type ="radio"  name ="radioGroup"/>

<input  type ="radio"  name ="radioGroup"/>

<input  type ="radio"  name ="radioGroup"/>

<input  type ="radio"  name ="radioGroup"/>

<input  type ="radio"  name ="radioGroup"/>

<input  type ="submit"/>

</form>

<script> 

var foo = (function(){

var radio_list = (function(){

var _list = [],

nodes = document.getElementsByTagName('input');

for(var i = 0; i < nodes.length; ++i){

var node = nodes[i];

if(node.type == 'radio' && node.name == 'radioGroup'){

if(node.attachEvent)

node.attachEvent('onclick', function(e){foo(e)} );

else if(node.addEventListener)

node.addEventListener('click', function(e){foo(e)}, false);

_list.push(node);

}

}

return _list;

})();

return function(e){

var o = (function(){

if(e) return e.target || e.srcElement;

else if(window.event) return e.srcElement;

})();

for(var i = 0; i < radio_list.length; ++i){

if(o == radio_list[i]){

alert(++i);

break;

}

}

}

})();

</script>

</body>

</html> 

你可能感兴趣的:(list,function,input)