开发者

Why doesn't this function work?

开发者 https://www.devze.com 2023-02-10 20:28 出处:网络
When i click \"test\" to frame is resized but when i click it again it doesnt resize back to its original size

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号