实际上onclick事件还是在radio上发生 只不过是通过js把 <a>标签的href属性的'#' 值 给动态的发生该表了而已 误以为是在<a> 标签上发生了onclick事件
<html>
<body>
<script type="text/javascript">
function changeIt(newLoc)
{
alert("hello"); //此条代码用于测试 这个回调函数 何时被调用
document.links[0].href = newLoc;
alert(document.links[0].href); //此条代码用于查看 是否a标签里的内容被动态修改过
}
</script>
<a href="#"> <h4>去看看</h4></a>
<input type="radio" name="choices" οnclick="changeIt('http://www.baidu.com')">百度<br>
<input type="radio" name="choices" οnclick="changeIt('http://www.qq.com')">腾讯<br>
<input type="radio" name="choices" οnclick="changeIt('http://www.sina.com')">新浪<br>
</body>
<!--
以下是第二种实现方式
<body>
<script type="text/javascript">
function f()
{
var radio = document.getElementsByName("radio");
for(var i = 0 ; i < radio.length ; i++)
{
if(radio[i].checked )
{
location = radio[i].value;
}
}
// location = radio.value;
}
</script>
<a href="#" οnclick="f()"> <h4>去看看</h4></a>
<input type="radio" name="radio" value="http://www.baidu.com" />百度<br/>
<input type="radio" name="radio" value="http://www.qq.com" /> 腾讯<br/>
<input type="radio" name="radio" value="http://www.sina.com" />新浪<br/>
</body>-->
</html>