[英]How do select a radio button with JavaScript?
I've tried select();
我试过select();
check();
and even .selected = true;
甚至.selected = true;
but I still haven't gotten around to selecting that radio button.但我仍然没有选择那个单选按钮。 Is there any way I can accomplish this?有什么办法可以做到这一点吗?
You have to use the checked
property:您必须使用checked
的属性:
element.checked = true;
Reference : HTMLInputElement
参考: HTMLInputElement
<input type=radio id='r'>
<script>
document.getElementById('r').checked=true;
</script>
Use.checked Use.checked
Maybe you could post your code and we could give you a more complete solution?也许您可以发布您的代码,我们可以为您提供更完整的解决方案?
To check a radio button I'm pretty sure it's.checked = true;要检查单选按钮,我很确定它是.checked = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.