[英]Checking radio boxes in javascript
I was just wondering is it possible to have a radiobox checkgroup just 1 on load? 我只是想知道是否有可能在装载时只有一个radiobox checkgroup? Only using JavaScript not using
check=checked
in html? 只使用JavaScript而不是在html中使用
check=checked
? I only know that. 我只知道。 Any help would be appreciated.
任何帮助,将不胜感激。 Cheers
干杯
EG 例如
<input type="radio" name="RadioGroup1" value="Phone" id="RadioGroup1_0" />Phone</label>
<input type="radio" name="RadioGroup1" value="Email" id="RadioGroup1_1" />Email</label>
<input type="radio" name="RadioGroup1" value="Mail" id="RadioGroup1_2" />Mail</label>
Try: 尝试:
document.querySelector("#RadioGroup1_0").click();
Example: http://jsfiddle.net/uk6cD/ 示例: http : //jsfiddle.net/uk6cD/
May be it is relevant for you to wrap it in the window' load
event handler: 可能是你将它包装在窗口'
load
事件处理程序中是相关的:
window.onload = function(){
document.querySelector("#RadioGroup1_0").click();
}
This may help, 这可能有所帮助,
$( document ).ready(function() {
$("#RadioGroup1_0").attr('checked','checked');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.