问题
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