日期:2014-05-16 浏览次数:20593 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script> function autoclick(){ var lnk = document.getElementById("auto"); lnk.click(); } function alertXX(){ alert("刚才一个链接被点击了,你没发现吗?") } </script> </head> <body onload="autoclick()"> <a href="#" id="auto" onclick="alertXX()">你不点我,会有人点我的</a> </body> </html>
------解决方案--------------------
直接上代码吧,给你写了一个小例子
<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')">
------解决方案--------------------
<a href="javascript:vote('simsim_poll', '2280');" title="??? 98671?"> </a>
点击也就是为了执行vote,
可以这样
setInterval(function(){vote('simsim_poll', '2280');},1000);//1s或者2s,自己决定