this works fine in Chrome, Firefox, etc but not in IE7. I get an error on line 16 that says: "Object doesn't support this action". it seems to fail at this line: image0.href = 'http://www.google.com';
if (document.images) {
image0 = new Image;
image1 = new Image;
image2 = new Image;
image3 = new Image;
image4 = new Image;
image5 = new Image;
image6 = new Image;
image7 = new Image;
image8 = new Image;
image0开发者_开发百科.src = '\/images\/image1.jpg' ;
image0.href = 'http://www.google.com';
image1.src = '\/images\/image2.jpg';
image1.href = 'http:\/\/www.google.com';
image2.src = '\/images\/image3.jpg';
image2.href = 'http:\/\/www.google.com';
image3.src = 'images\/image4.jpg';
image3.href = 'http:\/\/www.google.com';
image4.src = 'images\/image5.jpg';
image4.href ='http:\/\/www.google.com';
image5.src = 'images\/image6.jpg';
image5.href = 'http:\/\/www.google.com';
image6.src = 'images\/image7.jpg';
image6.href ='http:\/\/www.google.com';
image7.src = 'images\/image8.jpg';
image7.href = 'http:\/\/www.google.com';
image8.src = 'images\/image9.jpg';
image8.href = 'http:\/\/www.google.com';
} else {
image0 = '';
image1 = '';
image2 = '';
image3 = '';
image4 = '';
image5 = '';
image6 = '';
image7 = '';
image8 = '';
document.rollimg = '';
document.rollimg2 = '';
document.rollimg3 = '';
}
image0 = new Image;
Constructors are functions
image0 = new Image();
Images don't have an href
property, so this is meaningless:
image0.href = 'http://www.google.com';
And things that are just bad rather than broken.
image0 = new Image;
image1 = new Image;
image2 = new Image;
Use an array!
image0.src = '\/images\/image1.jpg' ;
The /
character has no special meaning in a JS string, it does not need to be escaped.
image0 = new Image;
Globals are evil. Use scoped variables.
var image0 = new Image;
… and limit them to the narrowest scope that makes sense for what you need to do.
The property src
is correct. The property href
does not exist: images are not links. Firefox and/or Chrome may be silently ignoring this, but it's not valid.
See this thread.
Also, there is no reason to escape forward-slashes.
精彩评论