2016-02-29 107 views

回答

0

使用jQuery:

function enter_key(ctrl, alt, shift, which) { 
    var e = $.Event("keydown"); 
    e.ctrlKey = false; 
    e.altKey = false; 
    e.shiftKey = false; 
    e.which = e.keyCode = 13; 
    $(document.documentElement || window).trigger(e); 
} 
var stop = false; 
for (var i=0; i<2000; ++i) { 
    if (!stop) { 
     enter_key(); 
    } 
} 

点击比较简单:

var stop = false; 
for (var i=0; i<2000; ++i) { 
    if (!stop) { 
     $('button').click(); 
    } 
} 

,你可以通过设置停止迭代:

stop = true; 
+0

感谢您的回答。我想要的东西,只是点击,我不应该设置ID或标签的名称想点击。我想要点击的东西! –

0

我的东西这件事,我发现了一个码即点击具体位置:

var elem = document.elementFromPoint(x, y); 

elem.addEventListener('click', function() { 
    console.log('clicked') 
}, false); 

var support = true; 

try { 
    if (new MouseEvent('click', {bubbles: false}).bubbles !== false) { 
     support = false; 
    } else if (new MouseEvent('click', {bubbles: true}).bubbles !== true) { 
     support = false; 
    } 
} catch (e) { 
    support = false; 
} 

setInterval(function() { 
    if (support) { 
     var event = new MouseEvent('click'); 
    }else{ 
     var event = document.createEvent('Event'); 
     event.initEvent('click', true, true); 
    } 
    elem.dispatchEvent(event); 
},1000); 

,我发现了获取鼠标的位置下面的代码:

function FindPosition(e) { 
    var posx = 0; 
    var posy = 0; 
    if (!e) var e = window.event; 
    if (e.pageX || e.pageY)  { 
     posx = e.pageX; 
     posy = e.pageY; 
    } 
    else if (e.clientX || e.clientY) { 
     posx = e.clientX + document.body.scrollLeft 
      + document.documentElement.scrollLeft; 
     posy = e.clientY + document.body.scrollTop 
      + document.documentElement.scrollTop; 
    } 
    // posx and posy contain the mouse position relative to the document 
    // Do something with this information 
} 

凭什么我用这个代码导入自动点击鼠标代码位置???

+0

在答案中提问并不好,你应该问另一个问题。 – jcubic