dispatchEvent 學(xué)習(xí)

1. createEvent(eventType)

參數(shù):eventType 共5種類型:
        Events :包括所有的事件.
        HTMLEvents:包括 'abort', 'blur', 'change', 'error', 'focus', 'load', 'reset', 'resize', 'scroll', 'select', 'submit', 'unload'.事件
        UIEvents :包括 'DOMActivate', 'DOMFocusIn', 'DOMFocusOut', 'keydown', 'keypress', 'keyup'.間接包含 MouseEvents.
        MouseEvents:包括 'click', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup'.
        MutationEvents: 包括 'DOMAttrModified', 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMCharacterDataModified', 'DOMNodeInsertedIntoDocument', 'DOMNodeRemovedFromDocument', 'DOMSubtreeModified'.

2. 在createEvent后必須初始化,為大家介紹5種對(duì)應(yīng)的初始化方法

  1. HTMLEvents 和 通用 Events:
    initEvent( 'type', bubbles, cancelable )
  2. UIEvents :
    initUIEvent( 'type', bubbles, cancelable, windowObject, detail )
  3. MouseEvents:
    initMouseEvent( 'type', bubbles, cancelable, windowObject, detail, screenX, screenY,
    clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget )
  4. MutationEvents :
    initMutationEvent( 'type', bubbles, cancelable, relatedNode, prevValue, newValue,
    attrName, attrChange )

3. 在初始化完成后就可以隨時(shí)觸發(fā)需要的事件了

targetObj.dispatchEvent(event)
使targetObj對(duì)象的event事件觸發(fā)
需要注意的是在IE 5.5+版本上請(qǐng)用fireEvent方法,還是瀏覽兼容的考慮

4. 更多

不過(guò)這個(gè)好像已經(jīng)廢棄了,現(xiàn)在推薦Eevent構(gòu)造函數(shù),查看有關(guān)Event的WebAPI,但是 Event構(gòu)造函數(shù)不兼容IE,所以如果要兼容IE的話還是離不開(kāi)上面的那個(gè)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容