下面的代码是从opencart 2生成的html
加载页面时未选择任何单选按钮。
如何选择Value="2“作为默认选中。(javascript或CSS)
<div id="payment-custom-field1" class="form-group custom-field" data-sort="0">
<label class="control-label">Invoice</label>
<div id="input-payment-custom-field1">
<div class="radio">
<label>
<input type="radio" value="2" name="custom_field[1]">
Receipt
</label>
</div>
<div class="radio">
<label>
<input type="radio" value="1" name="custom_field[1]">
Invoice
</label>
</div>
</div>
</div>使用javascript解决方案
(function() {
document.getElementsByName("custom_field[1]")[0].checked=true;
})();发布于 2016-09-06 21:02:16
<input type="radio" id="sample" value="2" name="custom_field[1]">
Receipt
</label>使用javascript:
document.getElementById("sample").checked = true;使用html:您可以简单地将checked属性添加到html元素
使用元素名称:
(function() {
document.getElementsByName("custom_field[1]")[0].checked=true;
})();发布于 2016-09-06 21:02:48
您可以简单地添加checked属性
<input type="radio" value="2" name="custom_field[1]" checked>
发布于 2016-09-06 21:26:30
使用javascript的解决方案是以下代码:
document.getElementsByName("custom_field1").checked=true;
谢谢你,潘迪亚酷
https://stackoverflow.com/questions/39349641
复制相似问题