IE下使用fireEvent
高级浏览器下使用dispatchEvent
示例代码如下
<!DOCTYPE html> <html> <head> <title>111</title> </head> <body> <select id='bbb' title="1111"> <option></option> <option value="b2">b2</option> <option value="b3">b3</option> </select> </body> <script type="text/javascript"> // 添加事件 var bbb = document.getElementById('bbb'); if(bbb.addEventListener){ bbb.addEventListener('change', function(){ console.log('aaaaaa'); }); } else{ bbb.attachEvent('onchange', function(){ console.log('aaaaaa'); }); } // 设置select默认值 bbb.value = 'b3'; // 手动触发事件 if (bbb.fireEvent){ bbb.fireEvent('onchange'); } else{ ev = document.createEvent("HTMLEvents"); ev.initEvent("change", false, true); bbb.dispatchEvent(ev); } // jquery触发 // bbb.trigger('change'); </script> </html>