我的问题很简单,我想用json重建一个html页面,但我不想破坏现有的html、框架等...
例子:
这段代码的结果是:
例子:
var myDiv = { tag : "div", style : "color:blue", class : "jj", content : "Hello"};
var myDiv = { tag : "div", style : "color:blue", class : "jj", content : "Hello"};
var param = { forbid : { tag : true, content : true } };
var createTag = function(o) {
var node = document.createElement(o.tag);
for (att in o) {
if (!param.forbid[att]) node.setAttribute(att, o[att]);
}
node.appendChild(document.createTextNode(o.content))
return node;
}
document.body.textContent = createTag(myDiv).outerHTML;
<div style="color:blue" class="jj"> Hello </div>
我怎样才能确保“标签”和“内容”不会影响现有/未来的属性?并且保持简单易懂?