如何从我的内容中转义 $?不断收到同样的错误。请帮忙。
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]);
}
}