This topic has been archived. It cannot be replied.
-
枫下家园 / 电脑用户 / 请教一个网页制作的问题。<form name=form1 id=form1>
<INPUT id=browser type=radio value=IE name=browser CHECKED>IE <INPUT id=browser type=radio value=Netscape name=browser>Netscape
</form>
我要在客户端用javascript对用户的选择进行一些处理,但是中的不到用户的选择。例如:
window.alert(document.form1.browser.value)
报告为undefined.
请DX们指点。多谢。
-forex(我认为);
2001-11-12
{332}
(#259355@0)
-
rename 'browser' to 'brower_type' !
-rootbear(喝点啤酒晕晕头);
2001-11-12
(#259370@0)
-
It does not help. :-(
-forex(我认为);
2001-11-12
(#259378@0)
-
Oops, 喝多了,browser1 for IE and browser2 for Netscape
using "if (document.form1.browser1.checked) {blah-blah; } else {ga-ga;}
-rootbear(喝点啤酒晕晕头);
2001-11-12
(#259408@0)
-
try document.forms[0].elements[0].value, whick works fine.
-totomorrow(tomorrow);
2001-11-12
(#259410@0)
-
没人理我?不会是都不会吧。还有个问题:javascript中相当于其他语言中的对字符串的trim()功能怎么实现?再次谢谢。
-forex(我认为);
2001-11-12
(#259373@0)
-
没有 trim 函数,你需要自己写。你是要 trim 字符串前面的空格还是后面的?
-violent_panda(大熊猫想吃香河肉饼);
2001-11-12
(#259399@0)
-
function trim(str){
while(str.charAt(0)==' ')
str=str.substring(1,str.length);
return str;
}
-rootbear(喝点啤酒晕晕头);
2001-11-12
(#259428@0)
-
你必须用 document.form1.browser[0].value 和 document.form1.browser[1].value 才对。
-violent_panda(大熊猫想吃香河肉饼);
2001-11-12
(#259392@0)
-
嘿嘿,悄悄的告诉你alert(document.form1.browser.value)是不能这样用的。
因为有两个browser,它怎么知道是取哪个value呀?
所以要这样:
for (var i = 0; i < document.forms[0].elements.length; i++)
{
var objElement = document.forms[0].elements[i];
if (objElement.name == "browser" && objElement.checked == true)
alert (objElement.value);
}
另外,JS里面是没有trim方法的,得自己写。
-xanada(㊣流水);
2001-11-12
{389}
(#259401@0)
-
算了,再给你送一个trimfunction trim(str)
{
var i=0;
if(str.length==0) return '';
while(str.charAt(i) == ' ')
{
i++;
if (i==str.Length) return '';
}
var j=str.length-1;
while(str.charAt(j) == ' ')
{
j--;
if (j==0) return '';
}
if (i>j) return "";
return str.substring(i, j+1);
}
-xanada(㊣流水);
2001-11-12
{302}
(#259436@0)
-
搞定,搞定。多谢啤酒,tomorrow,肉饼和流水(名单不分先後,成环形排列)。看来我对javascript还欠的多。其实我要的只是document.form1.browser[0].checked. 也是一时糊涂,总在value上绕圈子。
-forex(我认为);
2001-11-12
(#259469@0)