【发布时间】:2013-03-12 03:23:28
【问题描述】:
如何从我的内容中转义 $,?不断收到同样的错误。请帮忙。
TypeError: 'undefined' 不是对象(评估 'x[i].getElementsByTagName("line4")[0].childNodes[0].nodeValue')
// Populate the database
//
function populateDB(tx) {
alert("Populate!");
tx.executeSql('DROP TABLE IF EXISTS news');
tx.executeSql('CREATE TABLE IF NOT EXISTS news (id, title, line1, line2 TEXT, line3 TEXT, line4 TEXT, line5 TEXT)');
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","news.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("news");
for (i=0;i<x.length;i++)
{
p_id = x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
p_title = x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;
p_line1 = x[i].getElementsByTagName("line1")[0].childNodes[0].nodeValue;
p_line2 = x[i].getElementsByTagName("line2")[0].childNodes[0].nodeValue;
p_line3 = x[i].getElementsByTagName("line3")[0].childNodes[0].nodeValue;
p_line4 = x[i].getElementsByTagName("line4")[0].childNodes[0].nodeValue;
p_line5 = x[i].getElementsByTagName("line5")[0].childNodes[0].nodeValue;
tx.executeSql('INSERT INTO news (id,title,line1,line2,line3,line4,line5) VALUES (?,?,?,?,?,?,?)',[p_id,p_title,p_line1,p_line2,p_line3,p_line4,p_line5]);
}
}
【问题讨论】:
-
如果你像这样列出你的 for 循环,那么你需要你的评估输入。 empty(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;) continue;
-
@Marko ReferenceError: 找不到变量:空
-
这意味着您很可能只应用 childNodes[0].nodeValue 或 nodevalue
-
@Marko 你什么意思?已经是childNodes[0].nodeValue了?
-
我看到你只支持回到 IE5。不是那种限制吗?网景导航器呢?
标签: javascript sql cordova