Jquery 禁用单击鼠标悬停

Jquery 禁用单击鼠标悬停,jquery,Jquery,我有一个jquery游戏,我的成员一直在寻找获胜的方法。这是数字游戏 我制作了这个游戏,所以你不能在firefox上玩,不知道其他浏览器是否有和firefox相同的作弊工具 我遇到的第一个问题是,玩家只需将鼠标放在一个盒子上,直到他们的号码出现,然后单击它。为了解决这个问题(在stackoverflow上的genius的帮助下),我们制作了它,这样您就不能连续两次单击同一个框。 但现在也是同样的问题,他们只需移动到另一个盒子,保留鼠标,直到看到自己的号码。所以现在我需要这样做,如果他们在一个盒子

我有一个jquery游戏,我的成员一直在寻找获胜的方法。这是数字游戏

我制作了这个游戏,所以你不能在firefox上玩,不知道其他浏览器是否有和firefox相同的作弊工具

我遇到的第一个问题是,玩家只需将鼠标放在一个盒子上,直到他们的号码出现,然后单击它。为了解决这个问题(在stackoverflow上的genius的帮助下),我们制作了它,这样您就不能连续两次单击同一个框。 但现在也是同样的问题,他们只需移动到另一个盒子,保留鼠标,直到看到自己的号码。所以现在我需要这样做,如果他们在一个盒子上停留超过x秒,他们将无法点击这个盒子

倒计时计时器可能只是完成了这个任务,并消除了悬停脚本。请帮我做你能做的。这是剧本

    var hitCount = 0,
missCount = 0;

function IsNumeric(n) {
return !isNaN(n);
}

$("#getit").click(function() {
var hitCount = 0,
missCount = 0;
$('#misscount').text(0);
$('#hitcount').text(0);
$('#message').hide(100);        
$('#randomnumber').empty();
$('#randomnumber').show(300);       
var li = [],
    intervals = 0,
    n = parseInt($('#MyNumber').val());

if (IsNumeric(n)) {
   intervalId= setInterval(function() {
        li[intervals++ % li.length].text(Math.random() > .1 ? Math.floor(Math.random() * (10 + n) + (n / 2)) : n).attr('class', '')    ;
    }, <?php echo $time ?>);
}

$('#randomnumber').empty();

for (var i = 0; i < 7; i++) {
    li.push($('<li />').one('click', function() {
        BoxClick.call(this, n);
    }).appendTo('#randomnumber'));
}


function BoxClick(n) {
var $this = $(this);
$('#randomnumber li').unbind().one('click', function() {
        BoxClick.call(this,n);
});
$this.unbind();

if (!$this.hasClass('clicked')) {
    if (parseInt($this.text(), 10) === n) {
        $this.addClass('correct');
        $('#hitcount').text(++hitCount);
    } else {
        $this.addClass('wrong');
        $('#misscount').text(++missCount);
    }
}
            if(missCount==<?php echo $limit ?>){
               clearInterval(intervalId);
               $('#randomnumber').hide(300);

                $.ajax({
type : 'POST',
url : 'FBhighscore_hwnd.php',
dataType : 'json',
data: {
tgameid: $('#tgameid').val(),MyNumber: $('#MyNumber').val(),totalHits: hitCount
},
success : function(data){
$('#waiting').hide(500);
$('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
.text(data.msg).show(500);
if (data.error === true)
$('#loginForm').show(500);
else
$('#send').hide(500);       
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
$('#waiting').hide(500);
$('#message').removeClass().addClass('error')
.text('There was an error.').show(500);
$('#loginForm').show(500);
}
});

            }


$this.addClass('clicked');
}
return false;
});
var hitCount=0,
错误计数=0;
函数为数字(n){
返回!isNaN(n);
}
$(“#getit”)。单击(函数(){
var hitCount=0,
错误计数=0;
$(“#错误计数”)。文本(0);
$('hitcount')。文本(0);
$(“#消息”).hide(100);
$('#randomnumber').empty();
$('随机数')。显示(300);
var li=[],
间隔=0,
n=parseInt($('#MyNumber').val());
如果(是数字(n)){
intervalId=setInterval(函数(){
li[interval++%li.length].text(Math.random()>.1?Math.floor(Math.random()*(10+n)+(n/2)):n.attr('class','');
}, );
}
$('#randomnumber').empty();
对于(变量i=0;i<7;i++){
li.push($('
  • ').one('click',function(){ BoxClick.call(this,n); }).appendTo(“#随机数”); } 函数框单击(n){ var$this=$(this); $('#randomnumber li').unbind().one('click',function()){ BoxClick.call(this,n); }); $this.unbind(); if(!$this.hasClass('clicked')){ if(parseInt($this.text(),10)==n){ $this.addClass('correct'); $('#hitcount')。文本(++hitcount); }否则{ $this.addClass('error'); $(“#错误计数”).text(++错误计数); } } 如果(错误计数==){ clearInterval(intervalId); $(“#随机数”).hide(300); $.ajax({ 键入:“POST”, url:'FBhighscore_hwnd.php', 数据类型:“json”, 数据:{ tgameid:$('#tgameid').val(),MyNumber:$('#MyNumber').val(),总点击数:点击次数 }, 成功:功能(数据){ $('等待').hide(500); $('#message').removeClass().addClass((data.error==true)?'error':'success') .text(data.msg).show(500); 如果(data.error==true) $(#loginForm')。show(500); 其他的 $('#send')。隐藏(500); }, 错误:函数(XMLHttpRequest、textStatus、errorshown){ $('等待').hide(500); $('#message').removeClass().addClass('error')) .text(“出现错误”)。show(500); $(#loginForm')。show(500); } }); } $this.addClass('clicked'); } 返回false; });
  • 你可以很容易地记住他们盯着你悬停的时候。使用ID为“container”的跨度的简化示例,用户可以单击:

    jQuery(function($) {
    
      var container, n;
      var HOVER_THRESHOLD = 1000; // Milliseconds
    
      // Build the grid
      container = $('#container');
      for (n = 0; n < 16; ++n) {
        $("<span>0</span>").appendTo(container).data("hoverStart", 0);
      }
    
      // Watch for hovers and clicks on the elements
      container.find('span')
        .hover(startHover, stopHover)
        .click(handleClick);
    
      // At hover start, remember when we started
      function startHover() {
        $(this).data("hoverStart", new Date().getTime());
      }
    
      // At hover end, clear the hover thingy
      function stopHover() {
        $(this).data("hoverStart", 0);
      }
    
      // On click, check how long they've been hovering
      function handleClick() {
        var $this, startHover;
    
        $this = $(this);
        startHover = $this.data("hoverStart");
    
        // Hovering too long?
        if (startHover != 0
            && (new Date().getTime() - startHover) > HOVER_THRESHOLD) {
          // Yes
          $this.css("color", "red");
          setTimeout(function() {
            $this.css("color", "");
          }, 500);
        }
        else {
          // No, allow click
          $this.html(parseInt($this.html(), 10) + 1);
        }
      }
    });​
    
    jQuery(函数($){
    var容器,n;
    var HOVER_THRESHOLD=1000;//毫秒
    //构建网格
    容器=$(“#容器”);
    对于(n=0;n<16;++n){
    $(“0”).appendTo(container).data(“hoverStart”,0);
    }
    //注意元素上的悬停和单击
    container.find('span')
    .悬停(StartOver,stopHover)
    。单击(手动单击);
    //在悬停开始时,还记得我们什么时候开始的吗
    函数startHover(){
    $(this.data(“hoverStart”,new Date().getTime());
    }
    //在悬停结束时,清除悬停内容
    函数stopHover(){
    $(此).data(“hoverStart”,0);
    }
    //单击后,检查它们悬停了多长时间
    函数handleClick(){
    var$这个,StartOver;
    $this=$(this);
    startHover=$this.data(“hoverStart”);
    //徘徊太久?
    如果(StartOver!=0
    &&(新日期().getTime()-StartOver)>悬停(阈值){
    //对
    $this.css(“颜色”、“红色”);
    setTimeout(函数(){
    $this.css(“color”,”);
    }, 500);
    }
    否则{
    //否,允许单击
    $this.html(parseInt($this.html(),10)+1);
    }
    }
    });​
    

    或者,您可以使用计时器执行更复杂(但更主动)的操作:

    jQuery(function($) {
    
      var container, n;
      var HOVER_THRESHOLD = 1000; // Milliseconds
    
      // Build the grid
      container = $('#container');
      for (n = 0; n < 16; ++n) {
        $("<span>0</span>").appendTo(container).data("hoverTimer", 0);
      }
    
      // Watch for hovers and clicks on the elements
      container.find('span')
        .hover(startHover, stopHover)
        .click(handleClick);
    
      // At hover start, start a timer
      function startHover() {
        var $this = $(this);
        $this.data("hoverTimer", setTimeout(function() {
          $this.addClass("disabled");
        }, HOVER_THRESHOLD));
      }
    
      // At hover end, clear the timer
      function stopHover() {
        var $this, timer;
    
        $this = $(this);
        $this.removeClass("disabled"); // May or may not have it
        timer = $this.data("hoverTimer");
        if (timer != 0) {
          clearTimeout(timer);
          $this.data("hoverTimer", 0);
        }
      }
    
      // On click, check how long they've been hovering
      function handleClick() {
        var $this;
    
        $this = $(this);
    
        // Hovering too long?
        if ($this.hasClass("disabled")) {
          // Yes, disallow the click
        }
        else {
          // No, allow click
          $this.html(parseInt($this.html(), 10) + 1);
          // If you want to reset the hover timer on click:
          stopHover.call(this);
          startHover.call(this);
        }
      }
    });​
    
    jQuery(函数($){
    var容器,n;
    var HOVER_THRESHOLD=1000;//毫秒
    //构建网格
    容器=$(“#容器”);
    对于(n=0;n<16;++n){
    $(“0”).appendTo(container).data(“hoverTimer”,0);
    }
    //注意元素上的悬停和单击
    container.find('span')
    .悬停(StartOver,stopHover)
    。单击(手动单击);
    //在悬停启动时,启动计时器
    函数startHover(){
    var$this=$(this);
    $this.data(“hoverTimer”,setTimeout(function()){
    $this.addClass(“禁用”);
    },悬停(阈值);
    }
    //在悬停结束时,清除计时器
    函数stopHover(){
    var$this,timer;
    $this=$(this);
    $this.removeClass(“disabled”);//可能有也可能没有
    timer=$this.data(“hoverTimer”);
    如果(计时器!=0){
    清除超时(计时器);
    $this.data(“hoverTimer”,0);
    }
    }
    //单击后,检查它们悬停了多长时间
    函数handleClick(){
    var$这个;
    $this=$(this);
    //徘徊太久?
    如果($this.hasClass(“已禁用”)){
    //是,禁止单击
    }
    否则{
    //否,允许单击
    $this.html(parseInt($this.html(),10)+1);
    //如果要在上重置悬停计时器,请单击:
    停止悬停。呼叫(此);
    打电话(这个);
    }
    }
    });​
    

    但是,正如我在评论中所说的,你不能相信客户端发送给你的任何数据,因为有太多的工具用于调试web应用程序(这是一件很棒的事情!),或者只是完全伪造HTTP消息。在你的情况下,我认为不可能区分天才玩家和天才骗子(从数据中你可能会发现笨手笨脚的骗子)。

    “我制作了这个游戏,所以你不能在firefox上玩它,d