JQuery 中的鼠标悬停/悬停帮助

mouseover/hover help in JQuery

本文关键字:悬停 帮助 鼠标 JQuery      更新时间:2023-09-26
// ==UserScript==
// @name         Vulcun Jackpot Autoclicker
// @namespace    http://your.homepage/
// @version      0.35
// @description  enter something useful
// @author       You
// @match        https://vulcun.com/user/jackpot
// @grant        none
// ==/UserScript==
function enterContest() {
$('#submit-wager').each(function() {
    if($(this).attr('disabled') == 'disabled') {
       console.log("button disabled: skipped");
       return;
    }
    console.log(this);
    this.click();
    console.log("Button clicked");
});
}
setInterval(enterContest, 30000);

这个代码不是我的,只是为了清楚。代码确实有效,但是我想添加到它。第 19 行中的this.click();完成了它的工作,但我想添加一些东西,在它之前,一个类似于this.hover();this.mouseover();的东西,我是新手。正在单击的对象需要识别鼠标悬停在其上,然后才能单击它。在我必须将实际鼠标放在对象上之前,但是我希望该过程无需使用实际鼠标即可继续进行。我发现this.hover();this.mouseover();不是正确的功能。那么什么是正确的函数或代码呢?基本上,我想制作一个虚拟鼠标,这样对象就会认为它被我的真实鼠标触摸了,但事实并非如此。

编辑:固定版本:

// ==UserScript==
// @name         Vulcun Jackpot Autoclickerfix
// @namespace    http://your.homepage/
// @version      0.35
// @description  enter something useful
// @author       You
// @match        https://vulcun.com/user/jackpot
// @grant        none
// ==/UserScript==
function enterContest() {
$('#submit-wager').each(function() {
    if($(this).attr('disabled') == 'disabled') {
      console.log("button disabled: skipped");
       //return;
    }else{
        $(this).trigger('mouseover').trigger('click').trigger('mouseleave');
    }
});
}
$('#submit-wager').on('click', function(){
    console.log('Input Pressed');
});
$('#submit-wager').on('mouseover', function(){
    $(this).addClass('addThisClass');
    console.log('touch');
});
$('#submit-wager').on('mouseleave', function(){
    $(this).removeClass('addThisClass');
});
setInterval(enterContest, 30000);
您必须

each方法($(this)(中选择当前元素。将this.click();更改为$(this).click();。正如@Mohamed-Yousef所说,ID必须是唯一的。根据W3:

id 属性

id 属性指定其元素的唯一标识符 (ID(。这 值在元素的 home 子树中的所有 ID 中必须是唯一的 并且必须至少包含一个字符。该值不得包含 任何空格字符。

function enterContest() {
$('#submit-wager').each(function() {
    if($(this).attr('disabled') == 'disabled') {
       console.log("button disabled: skipped");
       return;
    }
    console.log($(this));
    $(this).click();
    console.log("Button clicked");
});
}
setInterval(enterContest, 30000);

首先,您遍历#submit-wager并且必须知道(ID必须是唯一的(,因此id="submit-wager"更改为class="submit-wager"并遍历它们

$('.submit-wager').each(function() {

2nd:对于触发mouseover您可以使用

$(this).trigger('mouseover');

演示如何处理此问题