簡體   English   中英

在復選框中顯示來自MySQL的是或否(0/1)

[英]Show true or false (0/1) from a mySQL in checkbox

<input type="text" id="A1" name="A1">

在上面的框中,從mysql放置0或1(在框中獲取)。 現在我想要:

值框= 0 >>復選框未選中

值框= 1 >>選中復選框

如何使用復選框(type =“ checkbox”)代替文本(type =“ text”)?

<input type="checkbox" id="A1" name="A1">

您可以像這樣檢查:

<?php
$box_val = 1; // rertive this value from database
?>
<input type="checkbox" id="A1" name="A1" <?=($box_val == 1) ? "checked" : "" ?>>

你可以這樣做:

<input id="A1" name="A1" checked="0" type="checkbox">
<script>
    $('#A1').prop("checked",$mySqlValue);
</script>

如果$mySqlValue==1 ,則將選中該框;如果$mySqlValue==0 ,則將不選中該框。

您可以使用js

document.getElementById("A1").checked = true;

你好Reza Hatami,

試試下面的代碼,
存儲數據中的$my_checkbox變量從mysql數據庫中檢索。

<?php
    $my_checkbox = 1;
?>
<input type="checkbox" id="Notification" name="Notification" <?php echo if($mycheckbox == 1) ? 'checked=""': ""; ?> />

也使用,但是在這個問題上是某些瀏覽器或php版本不支持,所以我建議使用上面的代碼。

<?php
   $my_checkbox = 1;
?>
    <input type="checkbox" id="Notification" name="Notification" <?=($my_checkbox == 1) ? "checked" : "" ?> />

希望我的回答對您有所幫助。 如有任何疑問,請發表評論。

<input type="checkbox"  id="A1" name="A1"   <?php if($value==1) echo 'checked="checked"'; ?> >

$value來自數據庫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM