在網頁中填寫表單是,單選、多選等input按鈕可以用label的for屬性實現點擊文字即可實現選擇。那么如果input radio或者input check旁邊不是文字而是圖片呢?其實也可以實現的,不過要加上一點JavaScript代碼了。
1、點擊文字實現選擇的效果
這個就是正常效果,不過也先介紹一下。
<input name="a1" id="a1" type="radio" /><label for="a1">西部E網(weste.net)</label>
<input name="a2" id="a2" type="radio" /><label for="a2">騰訊網(qq.com)</label>
這里用到label標簽的for屬性,內容與input的id相同即可。
2、點擊圖片實現選擇的效果
<label onclick="this.getElementsByTagName('input')[0].checked=true" style="cursor:hand"><input name="a1" id="a1" type="radio" /><img src="http://www.wsalc.com/images/logo.png"></label>
<label onclick="this.getElementsByTagName('input')[0].checked=true" style="cursor:hand"><input name="a1" id="a1" type="radio" /><img src="http://www.wsalc.com/images/logo.png"></label>

這樣就實現了讓圖片也能實現radio的Label功能。
