我有这个 HTML 代码:
<input type="radio" name="printTemplate" value="5" checked="checked">
<input type="radio" name="printTemplate" value="2">
如何在 JavaScript 中检查(勾选)值“2”? 我无法更改 html 代码,它是公共(public)网站。 这是此 radio 的 XPath,值为“2”
//*[@id="frmSubmit"]/table/tbody/tr[4]/td/p[2]/table/tbody/tr/td[1]/input[3]
最佳答案
您将添加 checked
属性。
<input type="radio" name="printTemplate" value="2" checked>
使用 jQuery,您也可以轻松地按值定位单选按钮
$("input[name=printTemplate][value=2]").prop("checked", true);
关于javascript - 如何在 JavaScript 中检查/勾选 radio 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17068357/