Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

AngularJS ng-class 指令


示例

更改 <div> 元素的类

<select ng-model="home">
    <option value="sky">Sky</option>
    <option value="tomato">Tomato</option>
</select>

<div ng-class="home">
    <h1>欢迎回家!</h1>
    <p>我喜欢它!</p>
</div>
自己尝试 »

定义和用法

ng-class 指令动态地将一个或多个 CSS 类绑定到 HTML 元素。

ng-class 指令的值可以是字符串、对象或数组。

如果它是一个字符串,则应包含一个或多个以空格分隔的类名。

作为对象,它应该包含键值对,其中键是要添加的类的类名,值是布尔值。只有当值设置为 true 时,才会添加该类。

作为数组,它可以是两者的组合。每个数组元素可以是字符串或如上所述的对象。


语法

<元素 ng-class="表达式"></元素>

所有 HTML 元素都支持。


参数值

描述
表达式 返回一个或多个类名的表达式。

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.