2016-08-22 60 views

回答

1

注意:請記住,id是唯一的。一個元素可以有一個id,它應該與其他元素不同。而不是id,如果你可以使用class。因爲,類可以用於任何數量的元素。

#one{ 
 
    width:100px; 
 
    height:100px; 
 
    margin:50px; 
 
    border:4px solid orange; 
 
    } 
 

 
#two{ 
 
    width:100px; 
 
    height:100px; 
 
    margin:50px; 
 
    border:8px solid red; 
 
    } 
 

 

 
#three{ 
 
    width:100px; 
 
    height:100px; 
 
    margin:50px; 
 
    border:6px solid blue; 
 
    } 
 

 

 
.all{ 
 
    background-color:pink; 
 
    }
<html> 
 
    <head> 
 
    <title></title> 
 
    </head> 
 
    
 
    <div class="all" id="one"></div> 
 
    <div class="all" id="two"></div> 
 
    <div class="all" id="three"></div> 
 
    
 

 
    <body> 
 
    </body> 
 
</html>

像上面的代碼,每個div有uniqueid。但同樣class,如果你做任何改變class,這將影響到所有的,它具有相同的類,名稱。 但id是不同的,款式僅適用於宣佈的id

2

ID應該是唯一的,並且頁面上只有一個元素應該有給定的ID。嘗試使用類來代替。

+0

謝謝你的answer.but有更多元素類與CSS。 –

+0

謝謝你,我得到了答案。 –

0

你不應該使用相同ID的所有元素的第一件事,ID應該是唯一的,是有史以來元素,

你應該在這種情況下使用類,因爲你要共享多個元素,你可以在同一個行爲通過使用類實現此目的,

+0

謝謝....我得到了answer.i更改了id的id,並更改了script.its working ....的類:D –

+0

Cool .... Sasindu Jayampathi –

0

嘗試爲每個元素使用不同的Id。

function myfun(firstId) { 
$('#pinsss').css({ background: "#0066ff"}); 
} 

function myfun(secondId) { 
$('#pinsss').css({ background: "#0066ff"}); 
}