边框颜色更改仅第一次工作

边框颜色更改仅第一次工作

本文介绍了边框颜色更改仅第一次工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作一个基于javascript的小游戏。



这里是



这将会执行

 <$ c 



解除绑定事件$ c> $('td')。unbind('click');

将点击事件绑定到 startGame() function

  $('td')。bind('click'); 

取消绑定 stopGame() function

  $('td')。unbind('click'); 

您的代码有问题: -



你在 startGame()函数中调用点击事件,因此第一次有一个 $('td'第二次调用 startGame()函数时有两个<$ c $ <$>

code code code code> $('td')。click()函数创建一个混乱



/ strong>





在函数 callStart()中,下面的代码在这个函数的结尾。

  $('td')。removeClass(insetBorderMiss); 
$('td')。removeClass(insetBorderCatch);


I am trying to make a javascript based small game.

Here is the Fiddle for the GAME

It is almost working except a few issues:-

Any improvement in code and suggestion are appreciable.

解决方案

Working DEMO

This will do the trick

unbind the click event in the starting

$('td').unbind('click');

bind the click event on the startGame() function

$('td').bind('click');

unbind the click event on the stopGame() function

$('td').unbind('click');

Problem with your code :-

you are calling click event in the startGame() function so for the first time you have one $('td').click() function

for the second time you call startGame() function there two $('td').click() function and so one which creates the mess

Suggestion for second point

DEMO

In function callStart() you have placed the below on the top instead place the below code at the end of the this function.

$('td').removeClass("insetBorderMiss");
$('td').removeClass("insetBorderCatch");

这篇关于边框颜色更改仅第一次工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 15:40