Created
May 20, 2015 09:47
-
-
Save shigwata/3f5319d1cb8cfc04b3bb to your computer and use it in GitHub Desktop.
Javascriptで強制的にイベントを発生させる方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// onChangeをエミュレート | |
var elem = document.getElementById("total"); | |
// ブラウザ判定 | |
if ( /*@cc_on ! @*/ false) { | |
// IEの場合 | |
elem.fireEvent("onchange"); | |
} else { | |
// Firefoxの場合 | |
var evt = document.createEvent("MouseEvents"); // マウスイベント作成 | |
evt.initEvent("change", false, true); // イベントの設定 | |
elem.dispatchEvent(evt); // イベントを強制的に発生 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment