2017-02-23 45 views
-1

我創建了一個自定義的矩形4種顏色如下,更改類background-color屬性與angular2

<div style=" width:400; height:400; float:left"> 
<div style="background-color:red; width:50%; height:50%; float:left"> 
</div> 
<div style="background-color:blue; width:50%; height:50%; float:right"> 
</div> 
<div style="background-color:green; width:50%; height:50%; float:left"> 
</div> 
<div style="background-color:orange; width:50%; height:50%; float:right"> 
</div> 
</div> 

我需要改變以下類的background-color屬性同上格者點擊上面的DIV的

<div class="eventBox eventBox__colorBar"></div> 
+0

請提供更多信息。我真的不明白你想要做什麼。 – developer033

回答

0

這是一個做你需要使用jquery的例子。 HTML:

<div style=" width:400; height:400; float:left"> 
    <div class="div-class" style="background-color:red; width:50%; height:50%; float:left"> 
    test1 
    </div> 
    <div class="div-class" style="background-color:blue; width:50%; height:50%; float:right"> 
    test 2 
    </div> 
    <div class="div-class" style="background-color:green; width:50%; height:50%; float:left"> 
    test3 
    </div> 
    <div class="div-class" style="background-color:orange; width:50%; height:50%; float:right"> 
    test4 
    </div> 
</div> 
<div class="eventBox eventBox__colorBar"> 
    test5 
</div> 

的jQuery:

$(".div-class").click(function() { 
    $(".eventBox").css('color', this.style.backgroundColor); 
}); 

我已經分配給每一個的div的類名,並迷上使用該類名稱的Click事件。

+0

問題與angular2 – Sajeetharan

+0

@Sajeetharan,你用'jQuery'標記它。 – developer033