SYNTAX_ERR:DOM 异常 12 - 嗯
我一直在为使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您在文档中使用非法的 id-attributes(HTML5 之前的非法),例如
2-slide
。修复它们。解释一下:
解决
元素的已知不当行为。 querySelectorAll()
选择器.slide
将在内部重写(通过使用元素的 id)。这将导致类似的结果:...并强制发生错误,因为 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:...and forces the error, because an ID may not start with a Number.
See the fiddle: http://jsfiddle.net/doktormolle/FGWhk/
如果您在 HTML5 摇滚幻灯片中搜索此错误后来到这里:
出于某种原因,他们删除了“to-build”类,其中包含以下内容:
这破坏了使用构建的所有幻灯片平台,甚至现在的 Google 演示也已损坏
只需更改default.js 的 220 行
一切都很好!
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:
That breaks all slide decks the use build, even the Google demo right now is broken
Just change line 220 of default.js to
all is well!
就我而言,它使用 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.
对我来说同样的问题,但在我的例子中,尝试从元素的属性
和 SYNTAX_ERR: DOM Exception 12 中获取元素仅发生在 Safari 上。所以我已经更改它以直接从类获取元素,现在工作正常。
Same problem to me but in my case a try to get elements from their attribute
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.
您可以像 applescript 中那样转义引号,然后在 safari 上就没有问题
You can escape the quotes like in applescript then no issue on safari