我試圖做一個井字棋遊戲,我目前正在選擇框自身的方面,但同時使用JQuery的:沒有選擇似乎並不正在工作。無法使用:不()選擇
function main(){
//Functions
$('.cell:not(.block)').click(function(){
$(this).addClass(color);
$(this).addClass('block');
if(color=='g'){color='r';}else{color='g';}
});
//Variables
var color = 'g';
}
$().ready(main);
html {
background-color:black;
color:white;
text-align:center;
}
.cell {
border: 1px solid white;
margin:1px;
width:30%;height:30%;
}
.g {background-color:lime;}
.r {background-color:red;}
#board {height:500px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>Tic Tac Toe</header>
<div id='board'>
<div class='cell'></div>
<div class='cell'></div>
<div class='cell'></div>
</div>
是什麼讓你覺得它不工作?似乎完美地工作。當我點擊一個'div'時,它會改變它的顏色。 – 2014-10-28 17:06:08
@FelixKling運行這個代碼片段,你不應該點擊一個'.cell',它有'.block'類,但你可以。 – 2014-10-28 17:07:02
@SterlingArcher:這是你自己的(很可能是真實的)解釋,但是OP應該仍然提供對問題的適當描述。 *「:不是選擇器似乎沒有工作」*不會告訴任何有關OP的期望。 (我只是迂腐;)) – 2014-10-28 17:07:55