我試圖調試,我不斷收到語法錯誤。我不確定這是怎麼回事。我試圖讓它在哪裏,如果我點擊一個附加到「$ color_cell」的對象,它會將atrr(「id」)推入到black_colors數組中。jQuery語法錯誤 - 意外的令牌
有人可以幫助我嗎?提前致謝。
<script src="jquery-1.6.2.js"></script>
<script type="text/javascript">
var ids = [];
var black_colors = [];
var blue_colors = [];
var brown_colors = [];
var gray_colors = [];
var green_colors = [];
var orange_colors = [];
var pink_colors = [];
var purple_colors = [];
var red_colors = [];
var teal_colors = [];
var white_colors = [];
var yellow_colors = [];
$(document).ready(function($) {
$(".btnColor").click(function(){
$(".color_cell").click(function(){
if $(this).attr("id") == "black"{
black_colors.push($(this).attr("id"));
}
});
});
});
</script>
<br>
<br>
<button type="button" class="btnColor" id="black">Black</button>
<button type="button" class="btnColor" id="blue">Blue</button>
<button type="button" class="btnColor" id="brown">Brown</button>
<button type="button" class="btnColor" id="gray">Gray</button>
<button type="button" class="btnColor" id="green">Green</button>
<button type="button" class="btnColor" id="orange">Orange</button>
<button type="button" class="btnColor" id="pink">Pink</button>
<button type="button" class="btnColor" id="purple">Purple</button>
<button type="button" class="btnColor" id="red">Red</button>
<button type="button" class="btnColor" id="teal">Teal</button>
<button type="button" class="btnColor" id="white">White</button>
<button type="button" class="btnColor" id="yellow">Yellow</button>
只有最後一個是真實的錯誤。 HTML5中的默認腳本語言是JavaScript(好吧,我們不知道它是否爲HTML5),並且jQuery將引用作爲第一個參數傳遞給ready處理程序。 –