![](/img/trans.png)
[英]How to select only one radio button at one time and deselect the others in javascript when the data are comes from database?
[英]How to select only one checkbox when data comes from database
我想授予用戶僅選擇一個復選框的權限。
$jsqla = mysql_query("select * from products where id='$product_id'") or die(mysql_error());
$jfeta = mysql_fetch_assoc($jsqla);
$formats = explode(";", $jfeta['formats']);
<div class="">
<?php foreach($formats as $v){ ?>
<label style="line-height: 1.25em;display: block;width: 100px;margin-right: 10px;float: left;">
<div class="fomat_buttons" style="border: 1px solid;border-radius: 9px;text-align: center;padding-top: 10px;padding-bottom:10px;padding-left: 3px;padding-right: 3px;border-color: #cccccc;font-family: 'SSemibold'; font-size: 13px; color: #44b7da;">
<input class="format_cheks" type="checkbox" value="<?php echo $v; ?>" style="visibility:hidden;"/>
<span style="margin:-17px auto auto 0px;display:block;"><?php echo $v; ?></span>
</div>
</label>
<?php } ?>
</div>
我想授予用戶僅選擇一個復選框的權限
聽起來像您想要一個單選按鈕組,而不是復選框。
<input class="format_cheks" type="radio" name="format_cheks" value="<?php echo $v; ?>" style="visibility:hidden;"/>
<!-- Changes here ---------------^^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
當用戶選中其他任何一個時,瀏覽器將自動取消選擇任何其他name="format_cheks"
單選按鈕。 提交表單后,僅發送一個 format_cheks
字段,其中包含選中的單選按鈕的值(如果有)。
<div><label><input type="radio" name="foo" value="1"> One</label></div> <div><label><input type="radio" name="foo" value="2"> Two</label></div> <div><label><input type="radio" name="foo" value="3"> Three</label></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.