编程语言
首页 > 编程语言> > javascript当中事件派发(dispatchEvent)的用法

javascript当中事件派发(dispatchEvent)的用法

作者:互联网

12.事件派发(dispatchEvent)

马克-to-win:下例仔细剖析了dispatchEvent。

例 12.1(DispatchEventFireIEFF.html)



<HTML>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</HEAD>
<BODY>
<select οnchange="alert('select onchange event');" id="select1">
    <option>1</option>
    <option>2</option>
</select>
<INPUT TYPE="button" value="按这" οnclick="clickButton()">
<script type="text/javascript">
    function clickButton() {undefined
        alert("click button");
        var t = document.getElementById('select1')
        if (document.all) {undefined
            t.fireEvent("onchange");
            alert("ie");
        }
        else {undefined
            var evt = document.createEvent('HTMLEvents');
            evt.initEvent('change', true, true);
            t.dispatchEvent(evt);
        }
    }
</script>
按button也会发出option的select事件
</BODY>
</HTML>
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_43650923/article/details/102985114

标签:undefined,派发,javascript,alert,dispatchEvent,var,document,evt
来源: https://www.cnblogs.com/malala/p/15612723.html