export function fireKeyEvent(el, evtType, keyCode) { var evtObj; if (document.createEvent) { if (window.KeyEvent) {//firefox 浏览器下模拟事件 evtObj = document.createEvent('KeyEvents'); evtObj.initKeyEvent(evtType, true, true, window, true, false, false, false, keyCode, 0); } else {//chrome 浏览器下模拟事件 evtObj = document.createEvent('UIEvents'); evtObj.initUIEvent(evtType, true, true, window, 1); delete evtObj.keyCode; if (typeof evtObj.keyCode === "undefined") {//为了模拟keycode Object.defineProperty(evtObj, "keyCode", { value: keyCode }); } else { evtObj.key = String.fromCharCode(keyCode); } if (typeof evtObj.ctrlKey === 'undefined') {//为了模拟ctrl键 Object.defineProperty(evtObj, "ctrlKey", { value: true }); } else { evtObj.ctrlKey = true; } } el.dispatchEvent(evtObj); } else if (document.createEventObject) {//IE 浏览器下模拟事件 evtObj = document.createEventObject(); evtObj.keyCode = keyCode el.fireEvent('on' + evtType, evtObj); } } fireKeyEvent(document.getElementById('aa'),'keydown',40); (function(){ function mySend111(msg){ fireKeyEvent(document.getElementsByClassName("chat-input border-box")[0],'keydown',32);}setInterval(mySend111,1000); }()); (function(){ var msgTarea=document.getElementsByClassName("chat-input border-box")[0]; var btn=document.getElementsByClassName("bl-button live-skin-highlight-button-bg bl-button--primary bl-button--small")[0]; function mySend(msg){ msgTarea.value= "生而为嬴,就要刷新你的视界观"; btn.click(); } setInterval(mySend,2520); }());