zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    cors
    js 离开页面
    移动端 touch
    eclipse
    java获取classpath以外的路径
    Javascript类型转换的规则
    myeclipse开发安装C++
    MyEclipse10中配置开发Python所需要的PyDev 绝对靠谱 不忽悠!
    POI生成EXCEL,公式不自动执行的有关问题
    POI中设置Excel单元格格式样式(居中,字体,边框等)
  • 原文地址:https://www.cnblogs.com/DZzzz/p/10391534.html
Copyright © 2011-2022 走看看