在 HTML 中,一個 class 值中可能包含一個詞列表,各個詞之間用空格分隔。例如,如果希望將一個特定的元素同時標記為重要(important)和警告(warning),就可以寫作:
<p class="important warning">
This paragraph is a very important warning.
</p>
這兩個詞的順序無關緊要,寫成 warning important 也可以。
我們假設 class 為 important 的所有元素都是粗體,而 class 為 warning 的所有元素為斜體,class 中同時包含 important 和 warning 的所有元素還有一個銀色的背景 。就可以寫作:
.important {font-weight:bold;}
.warning {font-weight:italic;}
.important.warning {background:silver;} //相當於兩個class有相同的樣式。
其實是一個DIV擁有兩個Class 空格並不是一個CLASS,用jquery你只需要$(".import")或 $(".warning")就可將其選定。