我有一个 XmlHttpRequest,它在函数外部时可以工作,如果我把它放在函数内部,我会得到第 94 行有 Uncaught SyntaxError: Unexpected token var 。
我的第 94 行是 var xmlhttp;
我用谷歌搜索了一下其他功能,它应该可以工作吗?
有什么想法吗?这就是我现在所拥有的。
function run(){
readXml();
}
function readXML{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.open("get", 'xml/stickers.xml', false);
xmlhttp.send();
var myXML = xmlhttp.responseXML;
stickers = myXML.getElementsByTagName("sticker");
for( i = 0; i<stickers.length; i++){
var idNod = (stickers[i].getElementsByTagName("id")[0].childNodes[0].nodeValue); /*Get the ID*/
var id = idNod;
var textNod = (stickers[i].getElementsByTagName("text")[0].childNodes[0].nodeValue); /* Text*/
add_sticker(textNod); /*Call creator function*/
var Xnod = (stickers[i].getElementsByTagName("x")[0].childNodes[0].nodeValue)+'px'; /*Get the x position Add PX for pixel*/
var Ynod = (stickers[i].getElementsByTagName("y")[0].childNodes[0].nodeValue)+'px'; /*Get the y position*/
var Znod = (stickers[i].getElementsByTagName("z")[0].childNodes[0].nodeValue); /*Get the y position*/
//console.log(Ynod)
//console.log(Xnod)
document.getElementById(id).style.top=Ynod; /* Style the position if the div. well done */
document.getElementById(id).style.left=Xnod;
document.getElementById(id).style.zIndex=Znod;
} }
最佳答案
您忘记了()
:
function readXML() {
// Here --------^
关于javascript - 函数内部出现意外的标记 var,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15611026/