Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/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
为什么这个jQuery函数没有';不行?变色_Jquery_Html - Fatal编程技术网

为什么这个jQuery函数没有';不行?变色

为什么这个jQuery函数没有';不行?变色,jquery,html,Jquery,Html,我正在尝试将我单击的图标的颜色更改为红色,而将其他按钮的颜色更改为无。但这不起作用。我知道语法是错误的,但我无法摆脱它 $("#appleIcon").click(function(e){ $("#appleIns").show(); $("#andIns").hide(); $(this).css("background-color", "red"); $("#andIcon").css("background-color", "none"); }); $("

我正在尝试将我单击的图标的颜色更改为红色,而将其他按钮的颜色更改为无。但这不起作用。我知道语法是错误的,但我无法摆脱它

$("#appleIcon").click(function(e){
    $("#appleIns").show();
    $("#andIns").hide();
    $(this).css("background-color", "red");
    $("#andIcon").css("background-color", "none");
});

$("#andIcon").click(function(e){
    $("#appleIns").hide();
    $("#andIns").show();
    $(this).css("background-color", "red");
    $("#appleIcon").css("background-color", "none");
});

背景色不是这样的东西:在CSS中没有


之所以没有效果,是因为没有背景色:没有。您可以将backgound color:transparent

css属性background color中存在错误:无。没有类似的事情。 正确的方法是:

$("#appleIcon").click(function(e){
    $("#appleIns").show();
    $("#andIns").hide();
    $(this).css("background-color", "red");
    $("#andIcon").css("background-color", "rgba(0,0,0,0)");
});

$("#andIcon").click(function(e){
    $("#appleIns").hide();
    $("#andIns").show();
    $(this).css("background-color", "red");
    $("#appleIcon").css("background-color", "rgba(0,0,0,0)");
});
$("#appleIcon").click(function(e){
        $("#appleIns").show();
        $("#andIns").hide();
        $(this).css("background-color", "red");
        $("#andIcon").css("background-color", "transparent");
    });

    $("#andIcon").click(function(e){
        $("#appleIns").hide();
        $("#andIns").show();
        $(this).css("background-color", "red");
        $("#appleIcon").css("background-color", "transparent");
    });
或者您可以试试这个:

$("#appleIcon").click(function(e){
    $("#appleIns").show();
    $("#andIns").hide();
    $(this).css("background-color", "red");
    $("#andIcon").css("background-color", "rgba(0,0,0,0)");
});

$("#andIcon").click(function(e){
    $("#appleIns").hide();
    $("#andIns").show();
    $(this).css("background-color", "red");
    $("#appleIcon").css("background-color", "rgba(0,0,0,0)");
});
$("#appleIcon").click(function(e){
        $("#appleIns").show();
        $("#andIns").hide();
        $(this).css("background-color", "red");
        $("#andIcon").css("background-color", "transparent");
    });

    $("#andIcon").click(function(e){
        $("#appleIns").hide();
        $("#andIns").show();
        $(this).css("background-color", "red");
        $("#appleIcon").css("background-color", "transparent");
    });

我建议您使用第一种方法,即将“背景色”设置为“rgba(0,0,0,0)”

这完全脱离上下文。您需要提供更多描述代码或文本。你不能无缘无故地称之为“this”。什么是
#appleIns
#andIns
。它们在你的JS中被引用,但我们没有提供HTML进行正确的故障排除。你还需要包含HTML和CSS才能回答这个问题。您的jQuery语法似乎很好。请尝试在此处重现此问题