代码改变世界

html checkbox

2012-01-25 18:00  youxin  阅读(312)  评论(0编辑  收藏  举报
<fieldset>
<legend>where do you live?</legend>
<input type="checkbox" id="arearural" name="areatypes[]" value="rural"/>
<label for="arearural">Rural </label>
<input type="checkbox" id="areasuburb" name="areatype[]" value="suburb"/>
<label for="areasuburb">Suburb</label>
<input type="checkbox" id="areacity" name="areatypes[]" value="city"/>
<label for="areacity">City </label>
</fieldset>

   Here the name attribute for all the checkmarks is the same and has square brackets prefi xed to it.The square brackets tell the system to send the checked values as an array. If you leave off the square   brackets, only the last checked value is sent. You could also have each name be different and without   the square brackets. In that case each name that was selected is sent as a separate value. With checkboxes,  only checked values are sent.

name数组以数组的形式发送选择的值,如果省略方括号,仅仅只有最后一个选择的值被发送。

 

You can also have individual checkboxes that are not part of a group. In the following instance,

if the box is checked, the form fi eld imagesonly is sent with the value of yes. If it is not checked,
nothing is sent:
<input type=”checkbox” id=”imagesonly” name=”imagesonly” value=”yes” />
<label for=”imagesonly”> Check here if you only want images.</label>