简体   繁体   English

如何获取整个HTML,包括属性和表单值

[英]How to get entire HTML including attributes and form values

I would like to get an entire form's (or div's) HTML including values of each control. 我想获取包括每个控件的值的整个表单(或div)的HTML。 I've tried innerHtml/outerHtml. 我试过innerHtml / outerHtml。 Although they give me the HTML, I'm not able to get the values for the controls. 尽管它们提供了HTML,但我无法获取控件的值。

Business scenario: I have a landing page with a placeholder ("loadHtml") for loading different html forms. 业务场景:我有一个带有占位符(“ loadHtml”)的登录页面,用于加载不同的html表单。 Based on user request, I retrieve standard html forms from the server and load them inside "loadhtml" div and have the user entire data in the various fields. 根据用户请求,我从服务器检索标准html表单,并将其加载到“ loadhtml” div中,并在各个字段中为用户提供整个数据。 Once the user is done with data entry and clicks "Save", I would like to extract the HTML (including textboxes & checkboxes) along with the values and send it to the server and store it as an HTML form. 用户完成数据输入并单击“保存”后,我想提取HTML(包括文本框和复选框)以及值,并将其发送到服务器并将其存储为HTML表单。

<div id="loadHtml"></div>

<div class="form-group">
  <div class="col-sm-offset-4">
    <button class="btn btn-success" ng-click="save()">Save</button>
   </div>
</div>

Well, If I understood well you want to get the entire HTML of another page and show it, so here's the way: 好吧,如果我理解得很好,您想获取另一个页面的整个HTML并将其显示出来,那么方法如下:

You can run a $http.get to the HTML page and show it simply using ngSanitize in your view. 您可以运行$http.get到HTML页面,并在视图中使用ngSanitize进行显示。

Here's an example: 这是一个例子:

 (function() { "use strict"; angular.module('app', ['ngSanitize']) .controller('mainCtrl', function($scope, $http) { $scope.html = ''; $scope.get_html = function() { $http.get('https://httpbin.org/').then( function(response) { $scope.html = response.data; }, function(response) { console.log(response); }); } }); })(); 
 <!DOCTYPE html> <html ng-app="app"> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular-sanitize.min.js"></script> </head> <body ng-controller="mainCtrl"> <span ng-bind-html="html"></span> <button type="button" ng-click="get_html()">Get entire HTML</button> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM