Mah*_*sin 6 html javascript css angularjs
我使用Angular.js构建了一个拖放HTML布局生成器.现在我想保存生成的HTML,CSS源代码,仅从设计中删除angular.js代码.他们使用angular.js生成HTML,CSS代码的任何解决方案?
在这里你可以使用jquery来获取你的html,如下所示
var allContent = $('.page-content').clone();
Run Code Online (Sandbox Code Playgroud)
通过这种方式删除多余的标签
//remove all angular class
allContent.find("div[class^='ng-'],div[class*='ng-']").each(function () {
//check and remove class
});
//remove all ng-model attribute ans so no
allContent.find('*[ng-model]').removeAttr('ng-model');
Run Code Online (Sandbox Code Playgroud)
清理你的 html 并获取所有 html
allContent.htmlClean();
var customPageContent = allContent.html();
Run Code Online (Sandbox Code Playgroud)
最后使用https://github.com/eligrey/FileSaver.js保存
var blob = new Blob([customPageContent], {
type: "application/xhtml+xml;charset=charset=utf-8"
});
saveAs(blob, fileName + ".html");
Run Code Online (Sandbox Code Playgroud)
额外功能
//clear your html
$.fn.htmlClean = function () {
this.contents().filter(function () {
if (this.nodeType != 3) {
$(this).htmlClean();
return false;
} else {
this.textContent = $.trim(this.textContent);
return !/\S/.test(this.nodeValue);
}
}).remove();
return this;
};
Run Code Online (Sandbox Code Playgroud)
我想这会对你有帮助。
| 归档时间: |
|
| 查看次数: |
166 次 |
| 最近记录: |