[英]Href to checked input radio
I have this code and I want after click to a href checked to radio box code: 我有此代码,我想在单击到href后选中单选框代码:
<p><a href=""><?php echo $result['answer1'];?><input type="radio" value="1" class='rgt' name='test1'/></a></p>
<p><a href=""><?php echo $result['answer2'];?><input type="radio" value="2" class='rgt' name='test2'/></a></p>
<p><a href=""><?php echo $result['answer3'];?><input type="radio" value="3" class='rgt' name='test3'/></a></p>
How can do it? 怎么办
HTML: HTML:
<div id="container">
<p><a href="">111111111111111<input type="radio" value="1" class='rgt' name='test1'/></a></p>
<p><a href="">2222222222222222<input type="radio" value="2" class='rgt' name='test2'/></a></p>
<p><a href="">3333333333333333<input type="radio" value="3" class='rgt' name='test3'/></a></p>
</div>
(all is placed in container, for easier targeting) (所有都放置在容器中,以便于定位)
JS: JS:
container=document.getElementById('container');
links=container.getElementsByTagName('a');
for(i=0;i<links.length;i++) {
links[i].addEventListener("click", function(e){
e.preventDefault();
if(this.childNodes[1].checked == true) {
this.childNodes[1].checked = false;
}
else {
this.childNodes[1].checked =true;
}
});
}
Demo: http://jsfiddle.net/ydu6h8vd/ 演示: http : //jsfiddle.net/ydu6h8vd/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.