angularjs中ng-attr的用法


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM