Home > Web Front-end > JS Tutorial > Summary of the advantages and disadvantages of the three calling methods of js

Summary of the advantages and disadvantages of the three calling methods of js

php中世界最好的语言
Release: 2018-05-12 14:02:48
Original
2016 people have browsed it

This time I will bring you a summary of the advantages and disadvantages of the three calling methods of js. What are the precautions when using the three calling methods of js. The following is a practical case, let's take a look.

This article describes the example codes of three ways of using js (inline js, internal js, external js). Interested friends can refer to it, as follows:

1. Inline js: js is not written separately

<!DOCTYPE html> 
<html lang="en"> 
<head> 
 <meta charset="UTF-8"> 
 <title>js使用方式1:行内js</title> 
</head> 
<body> 
<input type="button" value="点击有惊喜" onclick="javascript:alert(&#39;哈哈哈哈&#39;)"> 
<!--onclick:点击触发一个事件,alert:弹出一个对话框--> 
</body> 
</html>
Copy after login

2. Internal js: the entire page of the program in script can be used

<!DOCTYPE html> 
<html lang="en"> 
<head> 
 <meta charset="UTF-8"> 
 <title>js使用方式2:内部js</title> 
 <script type="text/javascript"> 
  //声明一个函数(整个文档都可以使用) 
  function surprise() { 
   alert('恭喜你中了一百万')/*弹出框*/ 
  } 
 </script> 
</head> 
<body> 
<input type="button" value="点击有惊喜" onclick="surprise()"><!--调用函数--> 
<input type="button" value="点击" onclick="surprise()"> 
</body> 
</html>
Copy after login

3. External js: Many HTML pages can call the set js page

<!DOCTYPE html> 
<html lang="en"> 
<head> 
 <meta charset="UTF-8"> 
 <title>js使用方式3:外部js</title> 
 <!--很多html页面都可以调用js4.js页面--> 
 <script src="../../js/js4.js" type="text/javascript" charset="utf-8"> 
 </script> 
</head> 
<body> 
<input type="button" value="点击" onclick="test()"> 
</body> 
</html>
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

How to view personal information and change password in vue

Detailed explanation of Vue array mutation implementation

The above is the detailed content of Summary of the advantages and disadvantages of the three calling methods of js. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template