所以如果你有这样的东西
<script type='text/undefined_type' src='hello.js'></script>
浏览器会忽略该hello.js
文件 [已测试]。但是,您如何使用 Javascript 并且仅使用 Javascript 来读取这个被忽略文件的内容?
我试过这个:
var hypeScriptFiles = new Array();
var allTag;
//get all script file
allTag = document.getElementsByTagName('*');
for (i=0;i<allTag.length;i++) {
if(allTag[i].getAttribute('type')) {
hypeScriptFiles.push('found one');
console.log(allTag[i].getAttribute('type'));
} else {
hypeScriptFiles.push('nope');
}
}
但实际上浏览器忽略了这一点。
- 控制台中什么也没有出现
- 应该记录一些东西 [脚本第 8 行]