Isa*_*wis 41 javascript html5 dom syntax-error domexception
我一直在为使用HTML5 Rock的幻灯片代码的客户端制作一个小型幻灯片/公共显示器.我遇到了一个DOM Exception 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);
};
Run Code Online (Sandbox Code Playgroud)
实例化SlideShow()
(main.js中的第521 行):
var slideshow = new SlideShow(queryAll('.slide'));
Run Code Online (Sandbox Code Playgroud)
调用queryAll('.slide')
返回一个包含类的所有幻灯片的数组.slide
.但是,当queryAll('.slide')
作为实例化参数传递时SlideShow()
,它会返回DOM Exception 12
错误.
有没有人见过这个?
Dr.*_*lle 54
您在文档中使用非法的id属性(在HTML5之前是非法的),例如2-slide
.修复它们.
为了解释:为了解决已知的不当行为的element.querySelectorAll()
选择.slide
将在内部重写(通过使用元素的id).这将产生类似的结果:
#2-slide .moreselectors
Run Code Online (Sandbox Code Playgroud)
...并强制执行错误,因为ID可能不以Number开头.
看小提琴:http://jsfiddle.net/doktormolle/FGWhk/
wes*_*bos 10
如果您在HTML5岩石幻灯片中搜索此错误后来到这里:
出于某种原因,他们使用以下内容删除了"to-build"类:
toBuild[0].classList.remove('to-build', '');
Run Code Online (Sandbox Code Playgroud)
这打破了所有幻灯片的使用版本,即使现在的谷歌演示也被打破了
只要改变线220的default.js到
toBuild[0].classList.remove('to-build');
Run Code Online (Sandbox Code Playgroud)
一切都很好!