• angularjs中向html页面添加内容节点元素代码段的两种方法


    第一种方式:原生JS向html页面添加内容节点元素代码段

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="utf-8">
        <script src="https://cdn.staticfile.org/angular.js/1.6.0/angular.min.js"></script>
    </head>
    
    <body>
    
        <div ng-app="myApp" ng-controller="personCtrl">
    
            <div id="test"></div>
        </div>
    
        <script>
          
            var app = angular.module('myApp', []);
            app.controller('personCtrl', function ($scope) {
             
                $scope.test = '<p><span style="border: 1px solid #000000;"><span style="text-decoration: line-through; font-family: 宋体, SimSun;"><em><strong>少时诵诗书所所所所所所所所所所所所所所所所所所所所所所所</strong></em></span><span style="text-decoration: line-through; font-family: 宋体, SimSun;"><em><strong><span style="text-decoration: line-through; font-family: 宋体, SimSun; border: 1px solid #000000;"></span></strong></em></span></span></p>'
                document.getElementById("test").innerHTML = $scope.test
         
            });
        </script>
    
    </body>
    
    </html>

     第二种方法:angular-sanitize方法向html页面添加内容节点元素代码段:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
    <script src="https://cdn.staticfile.org/angular.js/1.5.0-beta.0/angular-sanitize.min.js"></script></head>
    <body>
    
    <div ng-app="myApp" ng-controller="myCtrl">
    
    <p ng-bind-html="myText"></p>
    
    </div>
    
    <script>
    var app = angular.module("myApp", ['ngSanitize']);
    app.controller("myCtrl", function($scope) {
        $scope.myText = "My name is: <h1>John Doe</h1>";
    });
    </script>
    
    <p><b>注意:</b> 该实例包含了 "angular-sanitize.js" 文件,
    该文件移除 HTML 中的危险代码。</p>
    
    </body>
    </html>

  • 相关阅读:
    VSS與CSV區別
    办公室中节约时间
    C#中用Smtp發郵件
    关于分层结构的感悟(轉)
    Visual Studio.Net 技巧(轉)
    常用數據庫訪問方式比較
    Winows部署中一些內容說明
    适配器模式(Adapter Pattern)(轉)
    Vistual Studio 2005 sp1補丁的詳細內容
    感情 程序 祭 【转】
  • 原文地址:https://www.cnblogs.com/DZzzz/p/10391534.html
Copyright © 2020-2023  润新知