javascript 简单跳转 if (a = "baidu")//这句应该是if (a == "baidu")吧你改了试试看。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一步 我取到 a 的值 总是baidu 我哪些错了吗? getElementById("a") LZ你的ID呢,还有最好NAME不要同名 <html> <head> <title>测试</title> <script type="text/javascript"> function test() { var a;a = document.getElementById("tiao").value;alert(a);if (a == "baidu") window.location.replace("http://www.baidu.com"); else window.location.replace("http://www.g.cn");} </script> </head> <body> <form action="?" method="post" name="action"><input type="radio" name="tiao" id="tiao" value="baidu" />baidu<input type="radio" name="tiao" id="tiao" value="google" />google<input type="button" onclick="test()" value="给我跳" /> </form></body> </html>还是 取不到 google 为什么呢? radio 一组的 要起同名的啊 ---LZ---第一步 我取到 a 的值 总是baidu 我哪些错了吗?a = document.getElementById("a").value; 连id都没有a 从何而来?var a = document.getElementsByName("a")//a 是一个数组包括两个name为a 的inputa[0].value为第一个的值a[1].value用getElementById("a")-id必须全局唯一<input type="radio" name="a" value="baidu" /> //<input type="radio" name="b" value="google" /> 2个问题 : 你没有ID叫A的标签!NAME!=ID 虽然有些浏览器在 你定了 ID没有NAME时ID和NAME是一样的,但是不代表反国来也一样。2。 if (a = "baidu") 这是赋值操作,他的结果一定是TRUE ,并却A会在这2一步=“baidu” (问题就出在这) <html> <head> <title>测试 </title> <script type="text/javascript"> function test() { var obj,a; obj=document.getElementsByName("tiao"); if(obj!=null){ for(i=0;i<obj.length;i++){ if(obj[i].checked){ a=obj[i].value; alert(a); if (a == "baidu") window.location.replace("http://www.baidu.com"); else window.location.replace("http://www.g.cn"); } } }}</script> </head> <body> <form action="?" method="post" name="action"> <input type="radio" name="tiao" id="tiao1" value="baidu" />baidu <input type="radio" name="tiao" id="tiao" value="google" />google <input type="button" onclick="test()" value="给我跳" /> </form> </body> </html> 同名也不=同ID啊 !ID是唯一的 !! 这是当然的你不能这样取的两个单选按钮name全是a默认只会找第一个,你给两个按钮全加个ID 名字不同就能选读取了 jquery 表单验证问题 Map集合与List集合 求教jsp中<input>限制输入长度,和敏感字符过滤问题!!! 简单的正则表达 如何在JS中调用JAVA中的一个类的方法 Javascript中,怎样在字符串(如'123123aaa123')查找到子字符串(如'123')的个数,即出现的次数? 菜鸟问题,门外汉问 各位大哥,请帮帮忙吧!关于money转换的问题! 怎样在多行文本中将光标定位到任意行的行首 js里有没有类似vbscript里的chr()函数? 怎样动态设置插入的flash元素中的FlashVars值? 急急急,javascript事件对象的问题?
<head>
<title>测试</title>
<script type="text/javascript">
function test() {
var a;
a = document.getElementById("tiao").value;
alert(a);
if (a == "baidu")
window.location.replace("http://www.baidu.com");
else
window.location.replace("http://www.g.cn");
}
</script>
</head>
<body>
<form action="?" method="post" name="action">
<input type="radio" name="tiao" id="tiao" value="baidu" />baidu
<input type="radio" name="tiao" id="tiao" value="google" />google
<input type="button" onclick="test()" value="给我跳" />
</form>
</body>
</html>还是 取不到 google 为什么呢?
连id都没有a 从何而来?var a = document.getElementsByName("a")//a 是一个数组包括两个name为a 的input
a[0].value为第一个的值
a[1].value
用getElementById("a")-id必须全局唯一
<input type="radio" name="a" value="baidu" />
//<input type="radio" name="b" value="google" />
2。 if (a = "baidu") 这是赋值操作,他的结果一定是TRUE ,并却A会在这2一步=“baidu” (问题就出在这)
<head>
<title>测试 </title>
<script type="text/javascript">
function test() {
var obj,a;
obj=document.getElementsByName("tiao");
if(obj!=null){
for(i=0;i<obj.length;i++){
if(obj[i].checked){
a=obj[i].value;
alert(a);
if (a == "baidu")
window.location.replace("http://www.baidu.com");
else
window.location.replace("http://www.g.cn");
}
}
}
}
</script>
</head>
<body>
<form action="?" method="post" name="action">
<input type="radio" name="tiao" id="tiao1" value="baidu" />baidu
<input type="radio" name="tiao" id="tiao" value="google" />google
<input type="button" onclick="test()" value="给我跳" />
</form>
</body>
</html>