Home >Web Front-end >JS Tutorial >Summary of common methods for automatic execution of javascript functions_javascript skills

Summary of common methods for automatic execution of javascript functions_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:07:451336browse

Three common methods for automatically executing JS functions on web pages

In the Head area in HTML, there are the following functions:

<SCRIPT  LANGUAGE="JavaScript"> 
  functionn MyAutoRun()
  { 
   //以下是您的函数的代码,请自行修改先!
   alert("函数自动执行哦!"); 
  } 
</SCRIPT>

Next, we will focus on the above function and let it run automatically when the web page is loaded!

 ①The first method

Change the above code to:

<SCRIPT  LANGUAGE="JavaScript"> 
  functionn MyAutoRun()
  { 
   //以下是您的函数的代码,请自行修改先!
   alert("函数自动执行哦!"); 
  } 
  window.onload=MyAutoRun(); //仅需要加这一句
</SCRIPT>

 ②Second method

Modify the Body of the webpage to:

 05ae2b4cc5780328894ea910279ade0c

Or change to:

 a9a58ef1e6192c2cb0d663fe07e42b24

 ③The third method

Use JS timer to execute functions intermittently:

setTimeout("MyAutoRun()",1000); //Execute the MyAutoRun() function every 1000 milliseconds

Implementation method, change the top JS function to:

<SCRIPT  LANGUAGE="JavaScript"> 
  functionn MyAutoRun()
  { 
   //以下是您的函数的代码,请自行修改先!
   alert("函数自动执行哦!"); 
  } 
  setTimeout("MyAutoRun()",1000); //这样就行拉
</SCRIPT>

Other methods are more special, not commonly used, and not very versatile, so I won’t introduce them!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn