(继javascript)程序题

来源:百度知道 编辑:UC知道 时间:2024/06/22 22:48:47
四、程序题:
1、完成foo()函数的内容,要求能够弹出对话框提示当前选中的是第几个单选框。
<html>
<body>
<script>
function foo() {
// 在此处添加代码
return false;
}
</script>
<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>
</body>
</html>
2、填充注释部分的函数体,使得foo()函数调用弹出”成功”的

第一题:
function foo() {
for(var i=0; i<form1.radioGroup.length; i++){
if(form1.radioGroup[i].checked){
alert("第" + (i+1) + "个");
break;
}
}
return false;
}

第二题:
function reverse(str) {
temp = "";
for (var i = str.length-1; i >= 0; i--)
{
temp = temp + str.charAt(i);
}
return temp;
}