我有一个代码。它从这里加载文本:
<script type="text/mygamelevel" id="level1" src="levels/level1.txt">
000122341
124235245
154456567
</script>
mapa = loadFromFile("level1");
和 loadFromFile:
function loadFromFile(id) {
var level = document.getElementById(id).text;
var lines = level.split("\n");
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (!line.trim())
continue;
var letter = line.charAt(2);
alert("Second: " + letter + " ");
}
}
但它不起作用:/浏览器中的警报为空。为什么?