javascript當(dāng)中事件派發(fā)(dispatchEvent)的用法
事件派發(fā)(dispatchEvent)
馬克-to-win:下例仔細(xì)剖析了dispatchEvent。
馬克- to-win:馬克 java社區(qū):防盜版實(shí)名手機(jī)尾號: 73203。
例 12.1(DispatchEventFireIEFF.html)
<HTML>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</HEAD>
<BODY>
<select onchange="alert('select onchange event');" id="select1">
<option>1</option>
<option>2</option>
</select>
<INPUT TYPE="button" value="按這" onclick="clickButton()">
<script type="text/javascript">
function clickButton() {
alert("click button");
var t = document.getElementById('select1')
if (document.all) {
t.fireEvent("onchange");
alert("ie");
}
else {
var evt = document.createEvent('HTMLEvents');
evt.initEvent('change', true, true);
t.dispatchEvent(evt);
}
}
</script>
按button也會發(fā)出option的select事件
</BODY>
</HTML>