Javascript Can';不要改变按钮的颜色
尝试做一些似乎不起作用的超基本动作: HTMLJavascript Can';不要改变按钮的颜色,javascript,jquery,css,jquery-ui,Javascript,Jquery,Css,Jquery Ui,尝试做一些似乎不起作用的超基本动作: HTML <head> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script> </head> <body>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
</head>
<body>
<button style="margin: 10px; color:white; background-color: #4CAF50; font-size:40px;" type="button" id="aaa" > גבע</button>
</body>
按钮的颜色似乎没有改变。我做错了什么
谢谢
$('.thing')。在('click',function()上{
$(this.css('background','red');
});代码>
按钮
需要两次更改
Id选择在jquery中需要一个#
将backgroundColor
更改为backgroundColor
或backgroundColor
$(“#aaa”)。单击(函数(){
$(this.css('backgroundColor','white');
});代码>
将您的代码替换为:
$("#aaa").click(function () {
$(this).css('backgroundColor', 'white');
});
选择器规则有问题,选择器中缺少“#”用于id使用的。
用于类使用的
$("#aaa").click(function () {
$(this).css({'background-color':'white'});
});
将“backgroundcolor”
属性替换为“backgroundcolor”
那就行了
祝你好运这里有两个bug
将#
放在代码中缺少的id选择器之前
CSS(或DOM样式)属性应为backgroundColor
或backgroundColor
גבע
$(“#aaa”)。单击(函数(){
$(this.css('background-color','white');
});
按钮
是一个id选择器#aaa
גבע
$(“#aaa”)。单击(函数(){
$(this.css('background-color','white');
});
1) 将$(“aaa”)
更改为$(“aaa”)
:
对于id
选择器必须使用#
符号。
2) 将backgroundcolor
更改为backgroundcolor
$(“#aaa”)。单击(函数(){
$(this.css('background-color','white');
});代码>
בע
对于id使用“#”,对于“背景色”,使用“背景色”
$("#aaa").click(function () {
$(this).css('background-color', 'white');
});
$(“#aaa”)
,前缀#
表示“aaa未丢失aaa”#表示id?您不需要jQuery UI。单靠JQuery就足够了。事实上,您甚至可以在普通的旧javascriptI中更改按钮颜色。我已经解决了您的错误,请查看我的评论。$(“aaa”)
选择所有的
元素,这些元素都不是
$(this).css("background-color", "yellow");
$("#aaa").click(function () {
$(this).css('background-color', 'white');
});