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/4/video/2.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 Can';不要改变按钮的颜色_Javascript_Jquery_Css_Jquery Ui - Fatal编程技术网

Javascript Can';不要改变按钮的颜色

Javascript 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>

尝试做一些似乎不起作用的超基本动作:

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>        
    <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');
    });