function diqu(){
if(document.getElementById("sh").checked)
{
window.location.replace("https://www.baidu.com");
}
else if(document.getElementById("hz").checked)
{
window.location.replace("https://www.runoob.com");
}
else
{alert("您还没有选择所在地区噢!");}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文档标题</title>
</head>
<body>
<div class="cnt">
<h3>1、您属于哪个区域?</h3>
<ul>
<li><span> </span><label><input type="radio" id="sh" value="" />上海</label></li>
<li><span> </span><label><input type="radio" id="hz" value="" />杭州 </label></li>
</ul>
</div>
<button onclick="diqu()">试一试</button>
</body>
</html>
这是一个测评表单的部分,要实现用户选择杭州地区和上海地区跳转不同的网页,但是选择之后一直是报“您还没有选择所在地区噢!”,看上去像没有获取到值,想问问大家有没有解决方案?
测评链接地址:http://www.xakj365.com/aa/zlc...
我还有一个想法,是不是这个测评是一个一个来选择,那么到最后这个选择状态没有保存,所以js认为没有选择?
html 结构这样写才行哦:
你现在这样,所有都是 false 哦
实在改不了的话,也可以遍历
<li class="hover sel">
的这个.sel