标签:foreach 执行 oct hint ++ pre ons node utf-8
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div id="box"></div> <script> var boxEl = document.querySelector(‘#box‘) boxEl.innerHTML = ‘<script>console.log(1)<\/script><script>console.log(2)<\/script>‘ var script = document.createElement("script") var els = boxEl.getElementsByTagName("script") if (els.length) { //使用innerHTML生成的script节点不会发出请求与执行text属性 for (var i = 0, el; el = els[i++]; ) { var neo = script.cloneNode(false) //FF不能省略参数 Array.prototype.forEach.call(el.attributes, function(attr) { neo.setAttribute(attr.name, attr.value) })// jshint ignore:line neo.text = el.text el.parentNode.replaceChild(neo, el) } } </script> </body> </html>
使用innerHTML生成的script节点不会发出请求与执行text属性
标签:foreach 执行 oct hint ++ pre ons node utf-8
原文地址:http://www.cnblogs.com/jzm17173/p/6027540.html