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 d开发者_运维技巧own = 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()
. When the function is called, down
is reset to 0 every time again.
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;
}
}
I think down is a local variable and will be set to 0 each time the function is called.
精彩评论