我无法获得多个工作链接我一直得到未捕获参考错误:无法设置属性" imgToChange" null(...)有人可以告诉我我哪里出错了。
"use strict";
window.onload = rolloverInit;
function rolloverInit() {
for(var i = 0;i<document.links.length;i++) {
var linkObj =document.links[i];
if(linkObj,"id") {
var linkObj =document.getElementById(linkObj.caption);
if("imgObj") {
setupRollover(linkObj,"imgObj");
}
}
}
}
function setupRollover(theLink,theImage) {
theLink.imgToChange = theImage;
theLink.onmouseout = function() {
this.imgToChange.src = this.outImage.src;
}
theLink.onmouseover = function () {
this.imgToChange.src = this.overImage.src;
}
theLink.outImage = new Image();
theLink.outImage = textImage.src;
theLink.overImage = new Image();
theLink.overImage.src = "images/" + theLink.id + "Text.gif";
}
function setupRollover(theLink,australia) {
theLink.imgToChange = "australiamap";
theLink.onmouseout = function () {
this.imgToChange.src = this.outImage.src;
}
theLink.onmouseover = function() {
this.imgToChange.src = this.overImage.src;
}
theLink.outImage = new Image();
theLink.outImage = "images/australiamap.jpg";
theLink.overImage = new Image();
theLink.overImage.src = "images/" + caption.id + "adelaide5.jpg";
}
答案 0 :(得分:0)
您似乎将null传递给您的函数,请在调用它之前尝试检查:
function rolloverInit() {
for(var i = 0;i<document.links.length;i++) {
var linkObj =document.links[i];
if(linkObj,"id") {
var linkObj =document.getElementById(linkObj.caption);
if(linkObj !== null) { //check if linkObj is not null
setupRollover(linkObj,"imgObj");
}
}
}
}