通過label標(biāo)記實(shí)現(xiàn)單選框點(diǎn)擊文字也能選中

字號(hào):


    <label> 標(biāo)簽為 input 元素定義標(biāo)注(標(biāo)記)。label 元素不會(huì)向用戶呈現(xiàn)任何特殊效果。不過,它為鼠標(biāo)用戶改進(jìn)了可用性。如果您在 label 元素內(nèi)點(diǎn)擊文本,就會(huì)觸發(fā)此控件。就是說,當(dāng)用戶選擇該標(biāo)簽時(shí),瀏覽器就會(huì)自動(dòng)將焦點(diǎn)轉(zhuǎn)到和標(biāo)簽相關(guān)的表單控件上。<label> 標(biāo)簽的 for 屬性應(yīng)當(dāng)與相關(guān)元素的 id 屬性相同
    實(shí)例1:
    代碼如下:
    <label for="man">
    <input type="radio" value="男" name="man" id="man"/>
    男
    </label>
    <label for="man2">
    <input type="radio" value="女" name="man" id="man2"/>
    女
    </label>
    實(shí)例2:
    代碼如下:
    <input type="checkbox" name="Pages" value="Job" id="Job" ><label for="Job">添加、編輯招聘信息</label>
    <input type="checkbox" name="Pages" value="JobQuery" id="JobQuery" &gt;<label for="JobQuery">查詢、刪除招聘信息</label>
    <input type="checkbox" name="Pages" value="Technology" id="Technology" checked&gt;<label for="Technology">添加、修改科技項(xiàng)目</label>