Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery语法错误-意外标记_Javascript_Jquery_Syntax Error - Fatal编程技术网

Javascript jQuery语法错误-意外标记

Javascript jQuery语法错误-意外标记,javascript,jquery,syntax-error,Javascript,Jquery,Syntax Error,我正在试着调试,但我一直得到一个语法错误。我不知道这是怎么回事。我试着让它,如果我点击一个附加到“$color\u cell”的对象,它会将atrr(“id”)推到黑颜色数组中 有人能帮我吗?提前谢谢 <script src="jquery-1.6.2.js"></script> <script type="text/javascript"> var ids = []; var black_colors = []; var blue_colors = [];

我正在试着调试,但我一直得到一个语法错误。我不知道这是怎么回事。我试着让它,如果我点击一个附加到“$color\u cell”的对象,它会将atrr(“id”)推到黑颜色数组中

有人能帮我吗?提前谢谢

<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>&nbsp;
    <button type="button" class="btnColor" id="blue">Blue</button>&nbsp;
    <button type="button" class="btnColor" id="brown">Brown</button>&nbsp;
    <button type="button" class="btnColor" id="gray">Gray</button>&nbsp;
    <button type="button" class="btnColor" id="green">Green</button>&nbsp;
    <button type="button" class="btnColor" id="orange">Orange</button>&nbsp;
    <button type="button" class="btnColor" id="pink">Pink</button>&nbsp;
    <button type="button" class="btnColor" id="purple">Purple</button>&nbsp;
    <button type="button" class="btnColor" id="red">Red</button>&nbsp;
    <button type="button" class="btnColor" id="teal">Teal</button>&nbsp;
    <button type="button" class="btnColor" id="white">White</button>&nbsp;
    <button type="button" class="btnColor" id="yellow">Yellow</button>&nbsp;

var-id=[];
var black_colors=[];
var blue_颜色=[];
var brown_colors=[];
var gray_colors=[];
var green_colors=[];
var orange_colors=[];
var pink_colors=[];
var紫色_颜色=[];
var red_colors=[];
var teal_colors=[];
var白色颜色=[];
变量黄_颜色=[];
$(文档).ready(函数($){
$(“.btnColor”)。单击(函数(){
$(“.color\u单元格”)。单击(函数(){
如果$(this).attr(“id”)=“黑色”{
黑色。推送($(this.attr(“id”));
}
});
});
});


黑色 蓝色 棕色的 灰色 绿色 橙色 粉红色 紫色 红色 水鸭 白色 黄色的
我认为您的javascript语法不太正确。试试这个:

$(document).ready(function($) {
    $(".btnColor").click(function(){
        $(".color_cell").click(function(){
            if ($(this).attr("id") == "black") {
               black_colors.push($(this).attr("id"));
             }
        });
    });
});

我认为您的javascript语法不太正确。试试这个:

$(document).ready(function($) {
    $(".btnColor").click(function(){
        $(".color_cell").click(function(){
            if ($(this).attr("id") == "black") {
               black_colors.push($(this).attr("id"));
             }
        });
    });
});

您的代码中有许多错误

<script src="jquery-1.6.2.js"></script>
应成为:

<script type="text/javascript" src="jquery-1.6.2.js"></script>
$(document).ready(function() {
if ($(this).attr("id") == "black") {
以及:

应成为:

<script type="text/javascript" src="jquery-1.6.2.js"></script>
$(document).ready(function() {
if ($(this).attr("id") == "black") {
您还嵌套了两个
。click()
处理程序,这是不正确的

因此,最后你有:

<script type="text/javascript" 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() {
    $(".color_cell").click(function() {
        // Can't see any color_cell class in your markup
        // so no idea what you want to do if the DOM element with it is clicked
    });

    $(".btnColor").click(function() {
        if ($(this).attr("id") == "black") {
            black_colors.push($(this).attr("id"));
        }
    });
});
</script>

var-id=[];
var black_colors=[];
var blue_颜色=[];
var brown_colors=[];
var gray_colors=[];
var green_colors=[];
var orange_colors=[];
var pink_colors=[];
var紫色_颜色=[];
var red_colors=[];
var teal_colors=[];
var白色颜色=[];
变量黄_颜色=[];
$(文档).ready(函数(){
$(“.color\u单元格”)。单击(函数(){
//在标记中看不到任何颜色单元格类
//因此,如果单击带有它的DOM元素,您不知道要做什么
});
$(“.btnColor”)。单击(函数(){
if($(this.attr(“id”)=“black”){
黑色。推送($(this.attr(“id”));
}
});
});

您的代码中有许多错误

<script src="jquery-1.6.2.js"></script>
应成为:

<script type="text/javascript" src="jquery-1.6.2.js"></script>
$(document).ready(function() {
if ($(this).attr("id") == "black") {
以及:

应成为:

<script type="text/javascript" src="jquery-1.6.2.js"></script>
$(document).ready(function() {
if ($(this).attr("id") == "black") {
您还嵌套了两个
。click()
处理程序,这是不正确的

因此,最后你有:

<script type="text/javascript" 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() {
    $(".color_cell").click(function() {
        // Can't see any color_cell class in your markup
        // so no idea what you want to do if the DOM element with it is clicked
    });

    $(".btnColor").click(function() {
        if ($(this).attr("id") == "black") {
            black_colors.push($(this).attr("id"));
        }
    });
});
</script>

var-id=[];
var black_colors=[];
var blue_颜色=[];
var brown_colors=[];
var gray_colors=[];
var green_colors=[];
var orange_colors=[];
var pink_colors=[];
var紫色_颜色=[];
var red_colors=[];
var teal_colors=[];
var白色颜色=[];
变量黄_颜色=[];
$(文档).ready(函数(){
$(“.color\u单元格”)。单击(函数(){
//在标记中看不到任何颜色单元格类
//因此,如果单击带有它的DOM元素,您不知道要做什么
});
$(“.btnColor”)。单击(函数(){
if($(this.attr(“id”)=“black”){
黑色。推送($(this.attr(“id”));
}
});
});
而不是:if$(this).attr(“id”)=“黑色”

而不是:if$(this).attr(“id”)=“黑色”


只有最后一个才是真正的错误。HTML5中的默认脚本语言是JavaScript(好的,我们不知道它是否是HTML5),jQuery将对自身的引用作为第一个参数传递给ready处理程序。只有最后一个才是真正的错误。HTML5中的默认脚本语言是JavaScript(好的,我们不知道它是否是HTML5),jQuery将对自身的引用作为第一个参数传递给ready处理程序。