日期:2014-05-16  浏览次数:20464 次

Javascript 实现 自动单击
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>测试</title>
<style>
</style>
<script type="text/javascript">
 function fireEvent(element,event){
     if (document.createEventObject){
         // dispatch for IE
         var evt = document.createEventObject();
         return element.fireEvent('on'+event,evt)
     }
     else{
         // dispatch for firefox + others
         var evt = document.createEvent("HTMLEvents");
         evt.initEvent(event, true, true ); // event type,bubbling,cancelable
         return !element.dispatchEvent(evt);
     }
 }

 function _click(){
 fireEvent(document.getElementById('123'), 'click'); 
 }
</script>
</head>
<html>
<body onload="_click();">
ABCDE
<input type="button" name="123" id="123" value="按钮" onclick="alert('OK');">
</body>
</html>

?

?

来源:http://dearseven.blog.163.com/blog/static/10053792220101115112046377/