怎样重复运行上一次的函数,
点击了fn_1,再点击repeat_action就是运行fn_1();
点击了fn_2,再点击repeat_action就是运行fn_2();
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function fn_1(){
alert(1);
}
function fn_2(){
$("html").css("background-color","#eeeeee");
}
function fn_3(){
alert("hello");
}
function fn_4(){
$("html").css("background-color","transparent");
}

function repeat_acticon(){
//怎样重复上一次运行的动作?
//如:上一次运行fn_1(),则运行repeat_acticon()就是等于重复运行一次fn_1()
}
</script>
<button onclick="fn_1()">fn_1</button>
<button onclick="fn_2()">fn_2</button>
<button onclick="fn_3()">fn_3</button>
<button onclick="fn_4()">fn_4</button>
<button onclick="repeat_acticon()">repeat_acticon</button>

解决方案 »

  1.   

    定义一个全局变量num,在fn_1等函数中对它赋值,fn_1中就num=1然后再repeat_action根据num来调用fn_1等函数
      

  2.   

    <script type="text/javascript">
    var num=0
        function fn_1(){
            num=1;
            alert(1);
        }
        function fn_2(){
            num=2;
            $("html").css("background-color","#eeeeee");
        }
        function fn_3(){
            num=3;
            alert("hello");
        }
        function fn_4(){
            num=4;
            $("html").css("background-color","transparent");
        }
        
        function repeat_acticon(){
            if(num=1){fn_1()}//或者用Select Case 
            //怎样重复上一次运行的动作?
            //如:上一次运行fn_1(),则运行repeat_acticon()就是等于重复运行一次fn_1()
        }
    </script>
      

  3.   

    怎样获取funtion 名?
    js有没有办法返回fuction的名称?

     function fn_name(){
    return fn_name;
    }