Javascript 错误:“IE 中的”预期标识符、字符串或数字”
Javascript error: "Expected identifier, string or number" in IE
我正在制作一个基本的幻灯片,它在 Firefox 中工作正常,但是 IE 给了我以下错误:
Expected identifier, string or number script.js, line 26 character 4
Expected identifier, string or number script.js, line 26 character 4
Expected identifier, string or number script.js, line 24 character 4
Expected identifier, string or number script.js, line 25 character 4
Expected identifier, string or number script.js, line 25 character 4
Expected identifier, string or number script.js, line 25 character 4
Expected identifier, string or number script.js, line 35 character 3
Expected identifier, string or number script.js, line 35 character 3
Expected identifier, string or number script.js, line 35 character 3
Expected identifier, string or number script.js, line 35 character 3
Expected identifier, string or number script.js, line 35 character 3
Expected identifier, string or number script.js, line 35 character 3
Expected identifier, string or number script.js, line 35 character 3
这是我的代码(附有行号)。
1 $(document).ready(function(){
2
3 var slideshow = $("#slideshow");
4 var slides = slideshow.children(".slide");
5 var dimensions = {
6 position: slideshow.position(),
7 width: slideshow.width(),
8 height: slideshow.height(),
9 midX: slideshow.width()/2,
10 midY: slideshow.height()/2
11 };
12 var index = 0;
13
14 slides.each(function(number){
15 $(this).data("offset", {
16 left: dimensions.midX - ($(this).width()/2),
17 top: dimensions.midY - ($(this).height()/2)
18 });
19 $(this).css({
20 position: "absolute",
21 top: $(this).data("offset").top
22 });
23 if(number == 0)
24 {
25 $(this).css({left: $(this).data("offset").left + "px"});
26 }
27 else
28 {
29 $(this).css({left: dimensions.width + "px"});
30 }
31
32 slideshow.css({
33 position: "relative",
34 overflow: "hidden",
35 });
36 });
37
38 slideshow.bind('click', slideImages);
39
40 function slideImages(e){
41 e.preventDefault();
42 $(this).unbind('click', slideImages);
43 var direction = (e.pageX - dimensions.position.left < slideshow.width() / 2) ? "left" : "right";
44 var leftOffset = (direction == "left") ? dimensions.width : -dimensions.width;
45 slides.eq(index).animate({left: leftOffset}, 500, function() {
46 $(this).css({left: -leftOffset});
47 });
48
49 if (direction == "left")
50 index = (index == (0)) ? slides.length - 1 : index - 1;
51 else
52 index = (index == (slides.length - 1)) ? 0 : index + 1;
53
54 slides.eq(index).css({left: -leftOffset}).animate({left: slides.eq(index).data("offset").left}, 500, function() {
55 slideshow.bind('click', slideImages);
56 });
57
58 }
59
60 });
有谁知道是什么原因造成的?
厄运的邪恶逗号已经得到了你。
IE 不会原谅对象文字中的尾随逗号。
slideshow.css({
position: "relative",
overflow: "hidden", // <-- evil
});
像上面一样删除所有尾随逗号,你没事。
相关文章:
- jQuery在两个字符串标识符之间选择HTML
- JavaScript:将 URL 字符串转换为唯一标识符
- 需要标识符、字符串或数字
- SCRIPT1028:预期的标识符、字符串或数字
- 未捕获的语法错误:带有 .append() 字符串的意外标识符
- 生成动态 HTML,使用 JavaScript 更改名称值.错误:- 意外的字符串或标识符
- Javascript 错误:“IE 中的”预期标识符、字符串或数字”
- 未捕获的语法错误:意外的标识符,将字符串存储为索引
- IE8 上的 JS:删除终止逗号仍会给出“预期的标识符、字符串或数字”
- tzCheckbox需要标识符、字符串或数字
- IE 7需要标识符、字符串或数字
- 我可以使用一个空字符串作为对象标识符吗
- 需要标识符、字符串或数字.(Javascript)
- 如何在标识符名称和字符串变量中放置变量
- 流星空格-期望的标识符,数字,字符串,布尔值或null
- 如何在java脚本onclick标识符中安全地回显php字符串
- 如何转义/编码字符串到JavaScript标识符
- 使字符串在标识符后加粗
- 如何在不替换标识符的情况下获取2个标识符之间的字符串的值
- 为什么有可能用字符串作为标识符声明属性?做这件事的时候,在引擎盖下面是什么?