You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (typeof element === 'string') {
if (window.DOMParser) {
parser = new DOMParser()
docNode = parser.parseFromString(element, "text/xml")
}
element = docNode.firstChild
}
function treeHTML(element, object) {
object[''type"] = element.nodeName
var nodeList = element.childNode
if (nodeList != null) {
Object["content"] = []
for (var i = 0; i < nodeList.length; i++) {
if (nodeList[i].nodeType == 3) {
object["content"].push(nodeList[i].nodeValue)
} else {
object["content"].push({})
treeHTML(nodeList[i], object["content"][object["content"].length - 1)
}
}
}
}
if (element.attributes != null) {
if (element.attributes.length) {
object["attributes"] = {}
for (var i = 0; i < element.attributes.length; i++) {
object["attributes"][element.attributes[i].nodeName] = element.attributes[i].nodeValue
}
}
}
treeHTML(element, treeObject);
return (json) ? JSON.stringify(treeObject) : treeObject;
}
第641天 写一个方法将一个html字符串变成JSON树的形式
3+1官网
我也要出题
The text was updated successfully, but these errors were encountered: