本文實例講述了AngularJS使用ng-class動態(tài)增減class樣式的方法。分享給大家供大家參考,具體如下:
專注于為中小企業(yè)提供成都網(wǎng)站建設(shè)、做網(wǎng)站服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)榮昌免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
使用ng-class
可以實現(xiàn)動態(tài)地增減樣式:
<!DOCTYPE html> <html ng-app="formExample"> <head> <meta charset="UTF-8"> <title></title> <script src="../js/angular.js"></script> <script> angular.module('formExample', []) .controller('FormController', ['$scope', function($scope) { }]); </script> <style> .strike { text-decoration: line-through; } .bold { font-weight: bold; } .red { color: red; } </style> </head> <body> <div> <p ng-class="{strike: deleted, bold: important, red: error}">通過映射的方式</p> <input type="checkbox" ng-model="deleted">添加strike樣式<br> <input type="checkbox" ng-model="important">添加bold樣式<br> <input type="checkbox" ng-model="error">添加錯誤樣式 <hr> <p ng-class="style">使用字符串的方式</p> <input type="text" ng-model="style" placeholder="輸入 bold、 strike 或 red"> <hr> <p ng-class="[style1, style2, style3]">使用數(shù)組的方式</p> <input ng-model="style1" placeholder="輸入: bold, strike 或 red"><br> <input ng-model="style2" placeholder="輸入: bold, strike 或 red"><br> <input ng-model="style3" placeholder="輸入: bold, strike 或 red"><br> <hr/> </div> </body> </html>
更多關(guān)于AngularJS相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結(jié)》、《AngularJS入門與進階教程》及《AngularJS MVC架構(gòu)總結(jié)》
希望本文所述對大家AngularJS程序設(shè)計有所幫助。
當前名稱:AngularJS使用ng-class動態(tài)增減class樣式的方法示例
分享鏈接:http://chinadenli.net/article24/gdojce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、商城網(wǎng)站、ChatGPT、App設(shè)計、營銷型網(wǎng)站建設(shè)、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)