JavaScript 的无厘头错误...哪位大侠给解释下是什么造成的阿?
页面:
<div id= "arrange ">
<a href= "# " id= "aSmall " onClick= "clickSmall(); " class= "selected "> 小 </a>
<a href= "# " id= "aNormal " onClick= "clickNormal(); "> 中 </a>
<a href= "# " id= "aBig " onClick= "clickBig(); " > 大 </a>
</div>
js文件中:
function clickSmall()
{
var asmall = this.document.getElementById( "aSmall ");
var anormal = this.document.getElementById( "aNormal ");
var abig = this.document.getElementById( "aBig ");
asmall.className = "selected ";
anormal.className = " ";
abig.className = " ";
changePhoto (96);
}
function clickNormal()
{......}
function clickBig()
{......}
只有clickSmall会报错,调换一下实例的创建顺序:
function clickSmall()
{
var anormal = this.document.getElementById( "aNormal ");
var abig = this.document.getElementById( "aBig ");
var asmall = this.document.getElementById( "aSmall ");
......
}
问题解决;又尝试在其他在自己的方法中引用自己的函数中第一个创建自己的实例,如:
function clickNormal()
{
var anormal = this.document.getElementById( "aNormal ");
var abig = this.document.getElementById( "aBig ");
var asmall = this.document.getElementById( "aSmall ");
......
}
不报错运行良好
以前也遇到过相似的问题,类型完全像同的两个函数或方法,一个运行良好另一个报错...真TM想抽它...
------解决方案--------------------事出必有因
抽它也没用
个人认为应该跟获取对象顺序无关,能否贴全部代码
document前面就不要this.了
------解决方案--------------------testimg[i].style.width=size;
testimg[i].style.height=size;
改为
testimg[i].style.width=size + "px ";
testimg[i].style.height=size + "px ";