开发者

I want to run multiple functions using one function to do them all! any ideas?

function master() {
   moveEyes();
   monenoses();
   moveears();
   movefaces();
   movelips();
   moveglasses();
}

Above is all the functions i want to run from moveEyes to moveglasses开发者_运维问答. Function master is what i was going to call the main function. All the other functions work individually buy a bit a text like this:

// <p><a href="javascript:moveEyes()">Move to next pair of eyes</a></p>

But instead of having one line for each, I want one for all.

I tried doing what I have done at the top and then having one line like above but for the master function but it only moves the first line of moveEyes.

Can anyone help me please?


You misspelled monenoses.
Therefore, your function calls moveEyes, then throws an exception and stops.

You should use a debugging tool like Firebug or Chrome's Developer Tools, which will show these errors.


<p><a href="javascript:master()">Do all</a></p> should work.

It is most likely an error with one of your other functions that's causing the code to halt. Perhaps you should check your Javascript Console.


Another solution to reduce lines of code (just make sure you edit arr):

<script>

  function hi(){
    alert('hi');
  }

  function bye(){
    alert("bye");
  }

  var arr = ["hi", "bye"]
  for(i = 0; i < arr.length; i++){
   window[arr[i]]();
  }
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜