- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从 XMLHttpRequest 解析 XML 文件:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
loadItems(this);
}
};
xhttp.open("GET", "articles.xml", true);
xhttp.send();
function loadItems(xml) {
var xmlDoc = xml.responseXML;
var items = xmlDoc.getElementsByTagName("item");
for(var i = 0; i < items.length; i++){
//Next line is where the script crashes...
var newCategory = articles[i].parentElement.nodeName;
alert(newCategory);
}
}
我已经找到了我的错误:
var newCategory = articles[i].parentElement.nodeName;
我正在使用的 XML 结构:
<head>
<category>
<item>
<title>
foo
</title>
<contents>
bar
</contents>
</item>
</category>
<newcategory>
<item>
<title>
left
</title>
<contents>
right
</contents>
</item>
</newcategory>
</head>
这似乎适用于除 Internet Explorer 之外的所有其他浏览器,其中脚本在这一行静默崩溃。在其他浏览器中,newCategory 将具有字符串“category”或“newcategory”,具体取决于每个项目的父节点。
我查看了 Windows 文档,他们说支持parentElement 和nodeName 访问器,那么为什么会使脚本在IE 中崩溃呢?
最佳答案
在对 Internet Explorer 文档进行一些研究后,我发现有一个可以在 Firefox/Chrome/Opera 和 Explorer 中使用的 ParentNode 访问器。
var newCategory = articles[i].parentNode.nodeName;
关于javascript - x[i].parentElement.NodeName 适用于除资源管理器之外的所有内容。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45739775/
我有一个函数需要经过很多 parentElement获取 id。而不是写 if( element.parentElement.parentElement.parentElement.id == "ta
pg.myfunc = function(){ var i = 1, j = 2; this.selected = 1; xx.newObject = this.parentE
我不知道为什么,但是当我使用 .parentElement 时,我得到了未定义的信息,但在 Chrome 调试器中我看到有表单,错误在哪里? $('.ZamIlosc').each(function
HTML代码 anything anything anything 我有 3 个[按钮]
我在论坛上搜索了为什么在调用 getElementById 时我的 img 为 null,并且我已将脚本移到 img 下面,但我仍然得到图片为 null 的错误。 这是我的代码: fun
我正在从 XMLHttpRequest 解析 XML 文件: var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function
我使用的库名为hotel-datepicker。在我用纯 HTML 和 Javascript 在本地计算机上成功设置插件后,一切正常。但是当我将所有功能实现到自定义 WordPress 插件中后,出现
谁能简单的解释一下,经典DOM parentNode有什么区别?并在 Firefox 9 parentElement 中新引入 最佳答案 parentElement对 Firefox 9 和 DOM4
我正在使用此函数动态创建按钮 function addFormFields() { i += 1 const parentdiv = document.createEl
我有以下 DOM 结构 DIV 的溢出设置为自动,因此如果表格变大
不关心旧的浏览器回退。另外,不能使用库。 我有一个事件对象。我正在通过matchesSelector针对css选择器测试event.target: event['target'].matchesSel
我正在尝试使用 contentEditable=true 使用 javascript 构建一个 WYSIWYG 编辑器。我坚持的一点是,在 IE 上 document.selection.create
我有一个如下所示的 XML 文件: again Dave again
我有一个指令,点击一个按钮应该添加另一个指令,点击另一个按钮应该删除该指令。下面的代码添加了指令,但在单击“删除”按钮后,无法添加更多元素。 app.directive('chart', ['$com
我是一名优秀的程序员,十分优秀!