Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.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_Css_Jquery Ui - Fatal编程技术网

Javascript jquery可拖动并更改背景容器的颜色

Javascript jquery可拖动并更改背景容器的颜色,javascript,jquery,css,jquery-ui,Javascript,Jquery,Css,Jquery Ui,我得到了一个语法错误,因为很明显我做错了什么 代码如下: <style> body{margin:0 auto;} .draggable { width: 100px; height: 100px; padding: 0.5em;background-color:red;} </style> <script> $(function() { $( ".draggable" ).draggabl

我得到了一个语法错误,因为很明显我做错了什么

代码如下:

 <style>
    body{margin:0 auto;}
    .draggable { width: 100px; height: 100px; padding: 0.5em;background-color:red;}     

    </style>
    <script>
    $(function() {
        $( ".draggable" ).draggable();
    });
    var i=0;
    $(".draggable").each(function(i){
     if(i%2==0){
        #container("background-color:green");
       }
       i++;
       });
    </script>
 </head>
<body>

<div id="container" style="width:100%;height:400px;background-      color:#ccc;position:relative;">
<div class="draggable" class="ui-widget-content" style="margin-top:10%;margin-    left:1%;position:absolute;">
    <p>Drag me around</p>
</div>
<div class="draggable" class="ui-widget-content" style="margin-top:10%;margin-    left:20%;position:absolute;">
    <p>Drag me around</p>
</div>
<div class="draggable" class="ui-widget-content"style="margin-top:10%;margin-    left:33%;position:absolute;" >
    <p>Drag me around</p>
</div>
<div class="draggable" class="ui-widget-content"style="margin-top:10%;margin-    left:45%;position:absolute;" >
    <p>Drag me around</p>
</div>
<div class="draggable" class="ui-widget-content"style="margin-top:10%;margin-    left:60%;position:absolute;" >
    <p>Drag me around</p>
</div>
<div class="draggable" class="ui-widget-content" style="margin-top:10%;margin-    left:80%;position:absolute;">
    <p>Drag me around</p>
</div>
</div>

正文{页边距:0自动;}
.draggable{宽度:100px;高度:100px;填充:0.5em;背景色:红色;}
$(函数(){
$(“.draggable”).draggable();
});
var i=0;
$(“.draggable”)。每个(函数(i){
如果(i%2==0){
#容器(“背景色:绿色”);
}
i++;
});
把我拖来拖去

把我拖来拖去

把我拖来拖去

把我拖来拖去

把我拖来拖去

把我拖来拖去

在web developer工具中,语法错误如下:

#容器(“背景色:绿色”)

我需要做的是,当draggable div移出容器时,如果容器中剩余的draggable div的数量是奇数,则容器的背景色变为绿色

问候,, umbre gachoong

更换

#container("background-color:green");


谢谢你。进行了更改,但容器背景色未更改。我想这一定是我在这里使用的逻辑。移动。。。到代码的底部,就在正文结束之前。谢谢你。我现在移动了背景色为绿色,而没有移动可拖动的div。现在有人告诉我还有一个额外的要求。在将div计算为奇数或偶数之前,它们必须完全在容器中。如果它们一半在容器内或一半在容器外,则不计算在内。啊
$("#container").css("background-color", "green");