首先,我知道这是一个相对常见的错误,但似乎每次都有不同的解决方案,所以我希望有所帮助。这是我的javascript:
function showstuff(boxid, me, alternate, number){
document.getElementById(boxid).style.visibility="visible";
if (typeof number !== 'undefined') {
document.getElementById(boxid).style.height="number"+"px";
}
else { document.getElementById(boxid).style.height="215px";
}
document.getElementById(me).style.display="none";
document.getElementById(alternate).style.display="inline";
}
function hidestuff(boxid, me, alternate){
document.getElementById(boxid).style.visibility="hidden";
document.getElementById(boxid).style.height="0px";
if (typeof alternate !== 'undefined') {
document.getElementById(me).style.display="none";
document.getElementById(alternate).style.display="inline";
}
}
这是它引用的html:
<div><img onload="hidestuff('sched1'); hidestuff('sched2'); hidestuff('sched3');" src="/images/stories/calendar-ico.png" width="70px" border="0"/> Click on campus names to view schedules</div>
<img id='1reg' onclick="showstuff('sched1', '1reg', '1alt', 317);" width="389px" style="cursor: pointer;" src="/images/docs/scheduleparts/markhameast/olivetitle.jpg">
<img id='1alt' onclick="hidestuff('sched1', '1alt', '1reg';)" width="389px" style="cursor: pointer; display: none;" src="/images/docs/scheduleparts/markhameast/olivetitle.jpg">
<img id='sched1' width="389px" src="/images/docs/scheduleparts/markhameast/olivebody.jpg">
<img id='2reg' onclick="showstuff('sched2', '2reg', '2alt', 237);" width="389px" style="cursor: pointer;" src="/images/docs/scheduleparts/markhameast/libtitle.jpg">
<img id='2alt' onclick="hidestuff('sched2', '2alt', '2reg')" width="389px" style="cursor: pointer; display: none;" src="/images/docs/scheduleparts/markhameast/libtitle.jpg">
<img id='sched2' width="389px" src="/images/docs/scheduleparts/markhameast/libbody.jpg">
<img id='3reg' onclick="showstuff('sched3', '3reg', '3alt', 133);" width="389px" style="cursor: pointer;" src="/images/docs/scheduleparts/markhameast/centennialtitle.jpg">
<img id='3alt' onclick="hidestuff('sched3', '3alt', '3reg');" width="389px" style="cursor: pointer; display: none;" src="/images/docs/scheduleparts/markhameast/centennialbody.jpg">
<img onload="showstuff('sched1', '1reg', '1alt', 317)" id='sched3' width="389px" src="http://i.imgur.com/aBAtPM9.png">
我确信有一种更有效的方法来解决这个问题,但由于各种原因我需要保留这种方法。我的问题是,为什么我会收到语法错误?
非常感谢
答案 0 :(得分:4)
你有一个错误的分号:
<img id='1alt' onclick="hidestuff('sched1', '1alt', '1reg';)" width="389px" style="cursor: pointer; display: none;" src="/images/docs/scheduleparts/markhameast/olivetitle.jpg">
^^^^
HERE
它会在你的右括号前提前终止你的陈述。
<img id='1alt' onclick="hidestuff('sched1', '1alt', '1reg')" width="389px" style="cursor: pointer; display: none;" src="/images/docs/scheduleparts/markhameast/olivetitle.jpg">