[英]Why doesn't this function work?
When i click "test" to frame is resized but when i click it again it doesnt resize back to its original size 当我单击“测试”以调整框架大小时,但是当我再次单击它时,它不会重新调整为原始大小
function dropdownResize(){
var down = 0;
if(down == 0){
parent.document.getElementById('frameMain').rows = '84,84,*';
down = 1;
}
else{
parent.document.getElementById('frameMain').rows = '84,30,*';
down = 0;
}
}
<a onclick="dropdownResize()"> test</a>
It does not work because down
is defined within the scope of the function dropdownResize()
. 它不起作用,因为
down
是在dropdownResize()
函数的范围内定义的 。 When the function is called, down
is reset to 0 every time again. 调用该函数时,
down
会再次每次重置为0。
What you should do: (please note that this is a direct answer to your question and you should probably learn more about variable scope in order to prevent global variables as much as possible) 您应该做什么:( 请注意,这是对您问题的直接回答,并且您可能应该了解有关变量范围的更多信息,以便尽可能避免全局变量)
var down = 0;
function dropdownResize(){
if(down == 0){
parent.document.getElementById('frameMain').rows = '84,84,*';
down = 1;
}
else{
parent.document.getElementById('frameMain').rows = '84,30,*';
down = 0;
}
}
try: 尝试:
var down = 0;
function dropdownResize(){
if(down == 0){
parent.document.getElementById('frameMain').rows = '84,84,*';
down = 1;
}
else{
parent.document.getElementById('frameMain').rows = '84,30,*';
down = 0;
}
}
我认为down是一个局部变量,每次调用该函数时都将其设置为0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.