我想授予用户仅选中一个复选框的权限。
$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>
最佳答案
I want to give permission to the user to select only one check box
听起来你想要一个单选按钮组,而不是复选框。
<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>
关于javascript - 当数据来自数据库时如何只选择一个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27013005/