![](/img/trans.png)
[英]How I can uncheck checkbox when both of my inputs [type=text] cleared or empty?
[英]How can I make my checkbox not uncheck when clicked?
我有一個復選框,實際上是多個復選框,但我只希望一個復選框能夠將其設置為開和關。 但是要注意的是,我有一個POST發送一個PHP變量來確定是否在加載時選中了該框。 但是我使用的方法不允許我取消選中該框,因為IF $VAR="YES" CHECKBOX = CHECKED
,則我的JScript不會取消選中該框。
我不確定我的解釋是否能解決問題,所以我希望代碼能解決。
如果有人能看到解決此問題的簡單方法,我將不勝感激。 我只想要一個復選框,該復選框可以檢查POST是否已發送,而單擊時不選中。
謝謝。
<input type="checkbox" id="withvideo" name="withvideo" class='Mcheckbox' value="withvideo"
<?php if ($hasvideo==='yes'): ?> checked="checked" <?php endif; ?>
onclick="chbxhas(this); <?php $hasvideo==='yes'; ?>">
</input>
<label for="withvideo" class="checkboxes" title='Show Items With Videos'>With Video</label><i class="fa fa-video plusclass" ></i>
<---receiving page--->
if (isset($_POST['withvideo'])){$hasvideo="yes";}
else {$hasvideo="no";}
<---jscript--->
<script>
function chbxhas(objhas)
{
var that = objhas;
(objhas);
if(document.getElementById(that.id).checked === true) {
document.getElementById('withvideo').checked = false;
}
document.getElementById(that.id).checked = true;
}
</script>
嘗試這個
document.getElementById("withvideo").disabled = true;
代替
document.getElementById("withvideo").checked = true;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.