下一篇IE和FF的同级区别?

发布于 2024-10-10 00:18:59 字数 1032 浏览 0 评论 0原文

我刚刚在 raphaeljs 中编写了一个用于分层的 JavaScript 代码,它在 FF 上完美运行。 但在 IE 上不行。问题是 IE 对任何对象的 nextSibling 返回 null

如何正确使用它,或者 IE 中是否有 nextElementSibling 调用?

这是我用来更改对象顺序的代码片段:

n = items[selected_item_id].nextSibling.id;
if (n != '') {
  items[selected_item_id].insertAfter(items[n]);
}

<div id="consarea">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%">
<desc>Created with Raphaël</desc>
<defs/>
<rect x="188" y="100" width="200" height="200" r="10" rx="10" ry="10" fill="#ee8515" stroke="none" style="opacity: 1;" opacity="1"/>
<rect x="253" y="158" width="50" height="50" r="0" rx="0" ry="0" fill="#0080ff" stroke="none" style="opacity: 1;" opacity="1" id="0"/>
<rect x="230" y="140" width="50" height="50" r="0" rx="0" ry="0" fill="#c03022" stroke="none" style="opacity: 1;" opacity="1" id="1"/></svg>

这是上面的。我正在处理的html部分

I just wrote a javascript code for layering in raphaeljs it works perfectly on FF.
But it doesn't on IE. The problem is IE returns null for nextSibling for any object.

How does one use it correctly, or is there a nextElementSibling call in IE?

Here is the code fragment I used to change the order of objects:

n = items[selected_item_id].nextSibling.id;
if (n != '') {
  items[selected_item_id].insertAfter(items[n]);
}

<div id="consarea">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%">
<desc>Created with Raphaël</desc>
<defs/>
<rect x="188" y="100" width="200" height="200" r="10" rx="10" ry="10" fill="#ee8515" stroke="none" style="opacity: 1;" opacity="1"/>
<rect x="253" y="158" width="50" height="50" r="0" rx="0" ry="0" fill="#0080ff" stroke="none" style="opacity: 1;" opacity="1" id="0"/>
<rect x="230" y="140" width="50" height="50" r="0" rx="0" ry="0" fill="#c03022" stroke="none" style="opacity: 1;" opacity="1" id="1"/></svg>

here it is above. the piece of the html im working on

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

睫毛溺水了 2024-10-17 00:18:59

尝试使用以下功能。这是下一个兄弟的跨浏览器代码片段。

    function getNextElementSibling(CurrentElement) {
    if (CurrentElement.nextElementSibling) {
        return CurrentElement.nextElementSibling
    } else {
        do {
            CurrentElement = CurrentElement.nextSibling;
        } while (CurrentElement && CurrentElement.nodeType !== 1);
        return CurrentElement;
    }
}

Try to use the following function. It is a cross browser code snippet for next sibling.

    function getNextElementSibling(CurrentElement) {
    if (CurrentElement.nextElementSibling) {
        return CurrentElement.nextElementSibling
    } else {
        do {
            CurrentElement = CurrentElement.nextSibling;
        } while (CurrentElement && CurrentElement.nodeType !== 1);
        return CurrentElement;
    }
}
离鸿 2024-10-17 00:18:59

nextElementSibling 属性仅在 IE9 中受支持,在早期版本的 IE 中不受支持(您可以在此处查看

如果你愿意,你可以使用 JQuery 获取下一个同级,如下所示:

var sibling = $('#' + selected_item_id).next();
alert(sibling.attr('id'));

the nextElementSibling property is only supported in IE9 and not in previous versions of IE (you can check it here .

if you want you can get the next sibling using JQuery as follows:

var sibling = $('#' + selected_item_id).next();
alert(sibling.attr('id'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文