[英]checkbox default checked=“checked” is not working?
復選框默認選中不起作用! 我試圖修復它,但是我找不到錯誤在哪里? 所以在選中的頁面加載之后,在未選中的頁面加載之后! 我嘗試過
<div class="onoffswitch" style="margin: 0 auto;">
<input type="checkbox" class="avacheckbox onoffswitch-checkbox" id="AvButtonAutoGames" checked="checked"/>
<label class="onoffswitch-label" for="AvButtonAutoGames">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
然后
<div class="onoffswitch" style="margin: 0 auto;">
<input type="checkbox" class="avacheckbox onoffswitch-checkbox" id="AvButtonAutoGames" checked/>
<label class="onoffswitch-label" for="AvButtonAutoGames">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
要指定該值,請使用checked =“ true”,否則請不要指定該屬性。
Checked: <input type="checkbox" checked="true" /><br/> Not checked: <input type="checkbox" />
很難看到,但是您正在使用此語法定義復選框的值嗎?
document.getElementById('AvButtonAutoGames').checked = true
如果是這樣,這是不正確的-但在第一個JS示例中,您具有正確的prop
用法:
$('#AvButtonAutoGames').prop('checked', true)
就像HTML5
,要應用的語法只是<input checked>
或為了清楚起見而擴展為<input checked="checked">
。 缺少checked
屬性會導致輸入字段未選中。
只需將.checked=X
轉換為函數調用即可,它應該可以正常工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.