为什么这个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:transparentcss属性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语法似乎很好。请尝试在此处重现此问题