SYNTAX_ERR:DOM 异常 12 - 嗯

发布于 2024-12-03 05:56:04 字数 1880 浏览 5 评论 0原文

我一直在为使用 HTML5 Rock 的 幻灯片代码 的客户制作小型幻灯片/公共显示。我遇到了 DOM 异常 12 - 一个据称与 CSS 选择器相关的语法错误 - 在胡闹时......但我无法追溯到我在代码中所做的任何更改。我想这可能是我添加功能时发现的东西。

我已将其追溯到该对象(实时版本此处):

var SlideShow = function(slides) {
    this._slides = (slides || []).map(function(el, idx) {
      return new Slide(el, idx);
    });
    var h = window.location.hash;
    try {
      this.current = h;
    } catch (e) { /* squeltch */ }
    this.current = (!this.current) ? "landing-slide" : this.current.replace('#', '');
    if (!query('#' + this.current)) {
      // if this happens is very likely that someone is coming from
      // a link with the old permalink format, i.e. #slide24
      alert('The format of the permalinks have recently changed. If you are coming ' +
             'here from an old external link it\'s very likely you will land to the wrong slide');
      this.current = "landing-slide";
    }
    var _t = this;
    doc.addEventListener('keydown',
        function(e) { _t.handleKeys(e); }, false);
    doc.addEventListener('touchstart',
        function(e) { _t.handleTouchStart(e); }, false);
    doc.addEventListener('touchend',
        function(e) { _t.handleTouchEnd(e); }, false);
    window.addEventListener('popstate',
        function(e) { if (e.state) { _t.go(e.state, true); } }, false);
};

的实例化SlideShow()main.js 中的第 521 行):

var slideshow = new SlideShow(queryAll('.slide'));

调用queryAll('.slide') 返回类为 .slide 的所有幻灯片的数组。但是,当将 queryAll('.slide') 作为实例化 SlideShow() 的参数传递时,它会返回 DOM Exception 12 错误。

有人见过这个吗?

I have been working on a small slideshow / public display for a client that uses HTML5 Rock's Slideshow code. I have run into a DOM Exception 12 - a syntax error that is supposedly related to CSS selectors - while monkeying around with it... but I can't trace it back to any changes I made in the code. I am thinking it might be something that was uncovered as I added features.

I have traced it down to this object (live version here):

var SlideShow = function(slides) {
    this._slides = (slides || []).map(function(el, idx) {
      return new Slide(el, idx);
    });
    var h = window.location.hash;
    try {
      this.current = h;
    } catch (e) { /* squeltch */ }
    this.current = (!this.current) ? "landing-slide" : this.current.replace('#', '');
    if (!query('#' + this.current)) {
      // if this happens is very likely that someone is coming from
      // a link with the old permalink format, i.e. #slide24
      alert('The format of the permalinks have recently changed. If you are coming ' +
             'here from an old external link it\'s very likely you will land to the wrong slide');
      this.current = "landing-slide";
    }
    var _t = this;
    doc.addEventListener('keydown',
        function(e) { _t.handleKeys(e); }, false);
    doc.addEventListener('touchstart',
        function(e) { _t.handleTouchStart(e); }, false);
    doc.addEventListener('touchend',
        function(e) { _t.handleTouchEnd(e); }, false);
    window.addEventListener('popstate',
        function(e) { if (e.state) { _t.go(e.state, true); } }, false);
};

Instantiation of SlideShow() (line 521 in main.js):

var slideshow = new SlideShow(queryAll('.slide'));

Calling queryAll('.slide') returns an array of all the slides with an class of .slide. However, when passing queryAll('.slide') as a parameter for instantiating SlideShow(), it returns a DOM Exception 12 error.

Has anybody seen this before?

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

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

发布评论

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

评论(5

另类 2024-12-10 05:56:04

您在文档中使用非法的 id-attributes(HTML5 之前的非法),例如 2-slide 。修复它们。

解释一下:
解决 元素的已知不当行为。 querySelectorAll() 选择器 .slide 将在内部重写(通过使用元素的 id)。这将导致类似的结果:

#2-slide .moreselectors

...并强制发生错误,因为 ID 可能不以数字开头。

请参阅小提琴:http://jsfiddle.net/doktormolle/FGWhk/

You are using illegal id-attributes(illegal before HTML5) inside the document, e.g. 2-slide . Fix them.

To explain:
to solve the known misbehaviour of element.querySelectorAll() the selector .slide will be internally rewritten(by using the id of the element). This will result in something like that:

#2-slide .moreselectors

...and forces the error, because an ID may not start with a Number.

See the fiddle: http://jsfiddle.net/doktormolle/FGWhk/

夏末的微笑 2024-12-10 05:56:04

如果您在 HTML5 摇滚幻灯片中搜索此错误后来到这里:

出于某种原因,他们删除了“to-build”类,其中包含以下内容:

toBuild[0].classList.remove('to-build', '');

这破坏了使用构建的所有幻灯片平台,甚至现在的 Google 演示也已损坏

只需更改default.js220

toBuild[0].classList.remove('to-build');

一切都很好!

If you are coming here after searching for this error in HTML5 rocks slides:

For some reason they remove the class 'to-build' with the following:

toBuild[0].classList.remove('to-build', '');

That breaks all slide decks the use build, even the Google demo right now is broken

Just change line 220 of default.js to

toBuild[0].classList.remove('to-build');

all is well!

薄荷→糖丶微凉 2024-12-10 05:56:04

就我而言,它使用 self.postMessage(e.data);在使用网络工作者时在主线程中。

我知道这与OP的问题无关,但这是一个奇怪的错误,所以我将其留在这里,希望它对其他人有帮助。

In my case it was using self.postMessage(e.data); in the main thread while using web workers.

I know it's not related to the OP's issue, but it's an odd error so I'm leaving this here in hope it helps others.

执笔绘流年 2024-12-10 05:56:04

对我来说同样的问题,但在我的例子中,尝试从元素的属性

document.querySelectorAll('input[name="path"]')

和 SYNTAX_ERR: DOM Exception 12 中获取元素仅发生在 Safari 上。所以我已经更改它以直接从类获取元素,现在工作正常。

Same problem to me but in my case a try to get elements from their attribute

document.querySelectorAll('input[name="path"]')

and SYNTAX_ERR: DOM Exception 12 occurred only on Safari. So i've change it to get the element directly from class and now work fine.

青柠芒果 2024-12-10 05:56:04

您可以像 applescript 中那样转义引号,然后在 safari 上就没有问题

do JavaScript "document.querySelector('span[" & attrName & "=\"" & attrValue & "\"]').click();"

You can escape the quotes like in applescript then no issue on safari

do JavaScript "document.querySelector('span[" & attrName & "=\"" & attrValue & "\"]').click();"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文