Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
消息:在JavaScript中查询XML时出现对象必需错误_Javascript - Fatal编程技术网

消息:在JavaScript中查询XML时出现对象必需错误

消息:在JavaScript中查询XML时出现对象必需错误,javascript,Javascript,本例中的XML包含以下内容: test[_nObjectives].pool[j].feedbackCorrect = oQuestions[j].getElementsByTagName("feedbackCorrect")[0].firstChild.data; 执行该行代码时,会发生以下错误:Message:Object required 我不明白。标记就在那里,如果它是空的,则会发生错误,甚至有空格字符,但它不起作用。您得到错误是因为 <feedbackCorrect&

本例中的XML包含以下内容:

test[_nObjectives].pool[j].feedbackCorrect = 
oQuestions[j].getElementsByTagName("feedbackCorrect")[0].firstChild.data;

执行该行代码时,会发生以下错误:Message:Object required


我不明白。标记就在那里,如果它是空的,则会发生错误,甚至有空格字符,但它不起作用。

您得到错误是因为

  <feedbackCorrect>
  </feedbackCorrect>
正在返回该标记,.firstChild正在返回null,因为它没有子项

你确定你不想要吗

oQuestions[j].getElementsByTagName("feedbackCorrect")[0]

但当xml是这样时,它为什么工作:

oQuestions[j].getElementsByTagName("feedbackCorrect")[0].data
任意值

但是,当xml是这样的时候,它为什么工作:有值吗?
<feedbackCorrect>any value</feedbackCorrect>