首先,只能取出inline的JS内容,如果脚本是通过 src 加载进来的,这个是没办法取出的。
对于 inline 的 JS 内容,高端浏览器使用 textContent ,IE6/7/8 使用 innerText。下面是例子:
var script = document.getElementById( 's1' );
var text = script.textContent || script.innerText;
console.log( text ); // output alert(1);
首先,只能取出inline的JS内容,如果脚本是通过 src 加载进来的,这个是没办法取出的。对于 inline 的 JS 内容,高端浏览器使用 textContent ,IE6/7/8 使用 innerText。下面是例子:var script = document.getElementById( 's1' );var text = script.textContent || script.innerText;console.log( text ); // output alert(1);
搜索
javascript编程入门
js必学的十个技能
前端获取数据的方式
爬虫的正确编程方法
脚本模板大全
javascript语法讲解