HTML How to auto select a check box?

时光总嘲笑我的痴心妄想 提交于 2019-12-24 20:21:43

问题


I have the following HTML code:

<table border = 0 cellpadding=5 >

<tr>
<td><input type="checkbox" name="all_sizes" value="All">All<br></td>
<td><input type="checkbox" name="10mm" value="10mm">10mm<br></td>
<td><input type="checkbox" name="20mm" value="20mm">20mm<br></td>
<td><input type="checkbox" name="30mm" value="30mm">30mm<br></td>
<td><input type="checkbox" name="40mm" value="40mm">40mm<br></td>
</tr>
</table>

How would we go about selecting the first check box by default?


回答1:


Change this:

<td><input type="checkbox" name="all_sizes" value="All">All<br></td>

to this (add the keyword 'checked'):

<td><input type="checkbox" name="all_sizes" value="All" checked>All<br></td>



回答2:


Assuming that you've fetched your data from mysql using mysqli_query()

<td><input type="checkbox" name="all_sizes" value="All" <?php if($data['col_name'] == 'val') { echo 'checked'; }?>>Value</td>


来源:https://stackoverflow.com/questions/13427966/html-how-to-auto-select-a-check-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!