<script>
function triggerMouseEvent(element, eventType, canBubble) {
canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
if (element.fireEvent) {
element.fireEvent('on' + eventType);
}
else {
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent(eventType, canBubble, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
element.dispatchEvent(evt);
}
}
window.onload=function(){
var but = document.getElementById("test");
triggerMouseEvent(but,"click");
triggerMouseEvent(but,"mouseover");
}
</script>
<input type=button id="test" value="按钮" onclick="alert('onclick')" onmouseover="alert('onmouseover')">
|