【问题标题】:mouseover/hover help in JQueryJQuery 中的鼠标悬停/悬停帮助
【发布时间】:2015-11-17 02:43:46
【问题描述】:
// ==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);

【问题讨论】:

    标签: javascript jquery hover click mouse


    【解决方案1】:

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

    id 属性

    id 属性指定其元素的唯一标识符 (ID)。这 value 在元素的主子树中的所有 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);
    

    【讨论】:

    • 我得到了修复,但我不明白这个 ID 是怎么回事,@Mohamed-Yousef 说要使用 "$('.submit-wager').each(function() { " 但它不起作用。你说它需要修改但是当我查看你的代码时它保持不变。我迷路了。
    • @AAcat 我的意思是这个用户(@Mohamed-Yousef)也提到了你的问题。
    • 问题是,我不知道那是什么问题。我以前从未使用过 jQuery。你说身份证有问题,我不知道怎么解决。
    • @AAcat 我想this link can be helpful
    • 啊,我明白了,谢谢。顺便说一句,这个用户脚本用于的网站说它是一个 ID。所以我必须将其保留为“#”符号。
    【解决方案2】:

    首先你遍历#submit-wager并且你必须知道(ID必须是唯一的)所以将id="submit-wager"更改为class="submit-wager"并遍历它们

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

    第二个:对于触发器mouseover,你可以使用

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

    Demo to how to deal with this

    【讨论】:

    • 我试过你的代码,它不起作用。原来 ID 在网站上,与物理用户脚本无关。 (或者至少这是我的理论)我已经修复了你的代码,非常感谢顺便说一句,工作。
    • @AAcat 通过将我的代码 .submit-wager 更改为 #submit-wager 它只会选择第一个具有 id="submit-wager" 的元素,即使你使用 .each() 它也不会循环相同的 ID .. 因为你不应该有多个具有相同 ID 的元素 .. 祝你好运 :) .. 但是等待我们可以找到另一种解决方案 .. 你可以发布一个带有表单或提交按钮的简单 html 代码是吗??
    • 我的意思是,它现在可以工作了。所以这很好,对吧?无论如何感谢所有的支持。我的老师甚至无法解决这个问题。
    猜你喜欢
    • 2018-10-09
    • 2010-11-02
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多