<!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>