為什么name與onfocus的命名不可以一致呢?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 光標(biāo)聚焦事件 </title>
? <script type="text/javascript">
? ? /*function message(){
?alert("請(qǐng)選擇,您現(xiàn)在的職業(yè)!");
} */
? ? function star(){
? ? ? ? alert("請(qǐng)選擇你喜歡的明星!");
? ? ? ? }
? </script>
</head>
<body>
<!--請(qǐng)選擇您的職業(yè):<br>
? <form >
? ? <select name="career" onfocus="message()">?
? ? ? <option>學(xué)生</option>?
? ? ? <option>教師</option>?
? ? ? <option>工程師</option>?
? ? ? <option>演員</option>?
? ? ? <option>會(huì)計(jì)</option>?
? ? </select>?
? </form>
? ? -->
? ? 你喜歡的明星是:
<form>
? ? <select name="mingxing" onfocus="star()">
? ? ? ? <option>鹿晗</option>
? ? ? ? <option>吳亦凡</option>
? ? ? ? <option>胡歌</option>
? ? ? ? <option>霍建華</option>
? ? ? ? <option>魏晨</option>
? ? ? ? <option>黃渤</option>
? ? </select>
? ??
</form>
</body>
</html>
2016-07-14
onfocus是當(dāng)獲得焦點(diǎn)時(shí),出發(fā)里面的函數(shù),函數(shù)名稱一定和js中定義的一樣,否則就什么都不發(fā)生,而name是<select>這個(gè)標(biāo)簽的屬性,它還可以有ID, class等屬性。
2016-07-14
name 屬性規(guī)定 select 元素的名稱。用于對(duì)提交到服務(wù)器后的表單數(shù)據(jù)進(jìn)行標(biāo)識(shí),或者在客戶端通過 JavaScript 引用表單數(shù)據(jù)。
onfocus 屬性在元素獲得焦點(diǎn)時(shí)觸發(fā)。