fokker(独孤龙) barrydiu(巴索) 请进! 斑竹大人请手下留情,我以人格担保此举绝对不是倒分!问题解决了,答应给的分总应该给吧!解决问题:http://www.csdn.net/Expert/TopicView1.asp?id=992222 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 当你的radio只有一个的时候,你的程序及其它两位的程序都会出错,因为当只有一个的时候,这个radio已经不再是一个数组了,所以他们两位及你的代码都会出错,不信你拿掉其它的radio只剩下一个试试就知道了。 所以这里要用到另一个方法:<script language=javascript>function getRadioValue(RadioName){ var aa = document.getElementsByName(RadioName) for (var i=0; i<aa.length; i++) { if(aa[i].checked){alert(aa[i].value);return;} } alert("你一个都没有选择!");}</script> 一般情况下radio 都不会只使用一个(一个可以使用checkbox),当然如果坚持使用一个radio可用以下function :!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title> New Document </title><meta http-equiv="Content-Type" content="text/html; charset=iso8859-1"><script language="JavaScript"><!--function getRadioValue(place){ var objRadio = document.forms[0].elements[place]; var strValue = objRadio.value; if (strValue != undefined){ if (objRadio.checked){ return strValue; } else{ return null; } } for(i=0;i<objRadio.length;i++){ if(objRadio[i].checked){ return objRadio[i].value; } } return null;}//--></script></head><body><form name="form1" method=post action=""><!--<input type="radio" name="radioBtn" value="ok">ok<br>--><input type="radio" name="radioBtn" value="nok">not ok<br><input type="button" name="showvalue" value="Show Value" onclick="alert(getRadioValue('radioBtn'))"></form></body></html> barrydiu(巴索):这句在5.0下会出错strValue != undefined这样判断就好了:if(objRadio.value){ if (objRadio.checked){ return strValue; }} 1.<script>function getall(){ var i; var es = document.frmSearchUser.elements ; for(i=0;i<es.length;i++){ if (es[i].type=="radio"&&es[i].checked) alert(es[i].value) ; }}</script><form name="frmSearchUser"> <input type="radio" name="attr_0_Oper" value=">=" checked > >= <input type="radio" name="attr_0_Oper" value="=" > = <input type="radio" name="attr_0_Oper" value="<" > < <input type="radio" name="attr_0_Oper" value="<>" > <> <input type="radio" name="attr_0_Oper" value="between" > between </td> <input type="button" name="button" value="button" class="botton" onclick="getall()"></form>2.<script>function getall(){ var i; var es = document.all.tags("input") ; for(i=0;i<es.length;i++){ if (es[i].type=="radio"&&es[i].checked) alert(es[i].value) ; }}</script><form name="frmSearchUser"> <input type="radio" name="attr_0_Oper" value=">=" checked > >= <input type="radio" name="attr_0_Oper" value="=" > = <input type="radio" name="attr_0_Oper" value="<" > < <input type="radio" name="attr_0_Oper" value="<>" > <> <input type="radio" name="attr_0_Oper" value="between" > between </td> <input type="button" name="button" value="button" class="botton" onclick="getall()"></form>3.<script>function getall(){ var i; var es = document.frmSearchUser.attr_0_Oper ; if (es.length) for(i=0;i<es.length;i++){ if (es[i].checked) alert(es[i].value) ; } else if (es.checked) alert(es.value) ;}</script><form name="frmSearchUser"> <input type="radio" name="attr_0_Oper" value=">=" checked > >= <input type="radio" name="attr_0_Oper" value="=" > = <input type="radio" name="attr_0_Oper" value="<" > < <input type="radio" name="attr_0_Oper" value="<>" > <> <input type="radio" name="attr_0_Oper" value="between" > between </td> <input type="button" name="button" value="button" class="botton" onclick="getall()"></form> to fokker(独孤龙) :我在ie5.0 和nescape 4.79下测过,没有问题阿。你能不能贴一下报错信息。你的方法很好,ie和NN都ok. barrydiu(巴索):你的浏览器有没有禁止脚本调试?这是我以前发现的,现在手头上没有ie5.0的机器。我记得好像是说,undefined未定义 to fokker(独孤龙) :你的意见是对的,不能用strValue != "undefined" 或strValue != undefined我想我的浏览器没有报错是因为我装过ie6. 这个 字面常量 有问题 !!!!!!! 关于Ext comboBoxTree 在填写其它表单项是,值变空了 JavaScript 无法获取td的style.display属性 Function 对象问题,急!!! frameset里面页面如何访问父资源,并改写href? 用ajax模仿iframe? 按TAB键,A失去焦点,如何让B得到焦点?? 大家有没有好的js学习群.............请进.......... 谁帮忙解释一下这段代码?马上给分! 点击显示隐藏中的div中图片左右滚动 一个技术无关的帖子,推荐一下 请问如何在frameset中某个子窗口中实现在父窗口打开文件?
所以这里要用到另一个方法:
<script language=javascript>
function getRadioValue(RadioName)
{
var aa = document.getElementsByName(RadioName)
for (var i=0; i<aa.length; i++)
{
if(aa[i].checked){alert(aa[i].value);return;}
}
alert("你一个都没有选择!");
}
</script>
!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso8859-1">
<script language="JavaScript">
<!--
function getRadioValue(place){
var objRadio = document.forms[0].elements[place];
var strValue = objRadio.value;
if (strValue != undefined){
if (objRadio.checked){
return strValue;
}
else{
return null;
}
}
for(i=0;i<objRadio.length;i++){
if(objRadio[i].checked){
return objRadio[i].value;
}
}
return null;
}
//-->
</script>
</head><body>
<form name="form1" method=post action="">
<!--<input type="radio" name="radioBtn" value="ok">ok<br>-->
<input type="radio" name="radioBtn" value="nok">not ok<br>
<input type="button" name="showvalue" value="Show Value" onclick="alert(getRadioValue('radioBtn'))">
</form>
</body>
</html>
这句在5.0下会出错
strValue != undefined这样判断就好了:
if(objRadio.value){
if (objRadio.checked){
return strValue;
}
}
<script>
function getall(){
var i;
var es = document.frmSearchUser.elements ;
for(i=0;i<es.length;i++){
if (es[i].type=="radio"&&es[i].checked)
alert(es[i].value) ;
}
}
</script>
<form name="frmSearchUser">
<input type="radio" name="attr_0_Oper" value=">=" checked >
>=
<input type="radio" name="attr_0_Oper" value="=" >
=
<input type="radio" name="attr_0_Oper" value="<" >
<
<input type="radio" name="attr_0_Oper" value="<>" >
<>
<input type="radio" name="attr_0_Oper" value="between" >
between </td>
<input type="button" name="button" value="button" class="botton" onclick="getall()">
</form>2.
<script>
function getall(){
var i;
var es = document.all.tags("input") ;
for(i=0;i<es.length;i++){
if (es[i].type=="radio"&&es[i].checked)
alert(es[i].value) ;
}
}
</script>
<form name="frmSearchUser">
<input type="radio" name="attr_0_Oper" value=">=" checked >
>=
<input type="radio" name="attr_0_Oper" value="=" >
=
<input type="radio" name="attr_0_Oper" value="<" >
<
<input type="radio" name="attr_0_Oper" value="<>" >
<>
<input type="radio" name="attr_0_Oper" value="between" >
between </td>
<input type="button" name="button" value="button" class="botton" onclick="getall()">
</form>3.
<script>
function getall(){
var i;
var es = document.frmSearchUser.attr_0_Oper ;
if (es.length)
for(i=0;i<es.length;i++){
if (es[i].checked)
alert(es[i].value) ;
}
else
if (es.checked)
alert(es.value) ;
}
</script>
<form name="frmSearchUser">
<input type="radio" name="attr_0_Oper" value=">=" checked >
>=
<input type="radio" name="attr_0_Oper" value="=" >
=
<input type="radio" name="attr_0_Oper" value="<" >
<
<input type="radio" name="attr_0_Oper" value="<>" >
<>
<input type="radio" name="attr_0_Oper" value="between" >
between </td>
<input type="button" name="button" value="button" class="botton" onclick="getall()">
</form>
我在ie5.0 和nescape 4.79下测过,没有问题阿。
你能不能贴一下报错信息。你的方法很好,ie和NN都ok.
你的浏览器有没有禁止脚本调试?
这是我以前发现的,现在手头上没有ie5.0的机器。我记得好像是说,undefined未定义
你的意见是对的,不能用strValue != "undefined" 或strValue != undefined我想我的浏览器没有报错是因为我装过ie6.