前言
html中的屬性很多,同樣可以使用angularjs來定義:
ng-attr-(suffix)=只能使用變量定義
<div title="angularjs中的title">title</div><div ng-attr-title="angularjs中的title">title</div><!--這樣寫顯示不出來標題--><div ng-attr-title="'angularjs中的title'">title</div><!--這樣寫顯示不出來標題--><div ng-attr-title="{{titleStr}}">title</div><!--只能使用變量定義-->angular.module('myApp',[]) .controller('myCtrl',['$scope',function($scope){ $scope.titleStr = "angularjs中的title"; }]);ng-bind中使用字符可以將文字顯示出來
<span ng-bind=" 'angularjs中的title' ";
用法實例代碼:
<!DOCTYPE html><html lang="zh-CN" ng-app="app"><head> <meta charset="utf-8"> <title>ng-attr-(suffix)的用法</title> <link rel="stylesheet" href="../bootstrap.min.css"></head><body> <div> <p>1.正確做法:</p> <input type="text" ng-model="suffix" placeholder="請輸入input的type值"> (如:checkbox,radio,button,submit...) <br><br> 我將隨著輸入的值變化:<input ng-attr-type="{{ suffix }}"> </div> <div style="margin-top: 20px;"> <p>2.錯誤做法:cx="{{ cx }}"</p> <p>這里的錯誤做法,并非真正的錯誤做法,只是有時瀏覽器會對屬性會進行很苛刻的限制,所以不建議這樣做。比如svg</p> <div style="border: 1px solid red;width: 200px;height: 200px;"> <svg> <circle cx="{{ cx }}"></circle> </svg> 這里瀏覽器會報錯 </div> 改為:ng-attr-cx="{{ cx }}" <div style="border: 1px solid green;width: 200px;height: 200px;"> <svg> <circle ng-attr-cx="{{ cx }}"><circle> </svg> 這里不會報錯 </div> </div> <script src="../angular.min.js"></script> <script> angular.module('app', []) </script></body></html>總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
新聞熱點
疑難解答