JS_01 Basic usage of js

JavaScript

JS composition

ECMAScript (Basic Syntax)

​ describes the grammar and basic objects of the language

DOM (Document Object Model)

​ Describes the methods and interfaces for processing web content,

BOM (Browser Object Model)

​ Describes the methods and interfaces for interacting with the browser

Basic usage

Inline JS: write in element tag

Internal JS:<script>***</script>

External JS file: hello.js file is imported with script tag

<body>
<!--
JS的三种使用方式
1. 行内JS 在html标签上直接写JS代码
2. 内部JS 在<script></script>写JS代码 ,可放置在页面任意位置
3. 外部JS 定义JS文件,通过<script></script>的src属性引入JS文件
注意:如果script标签设置了scr属性,则script标签内容不再生效
-->
<!--行内JS-->
<button onclick="alert('hello World');" type="submit">提交</button>
<!--内部JS-->
<script type="text/javascript">
  alert("这是一个按钮");
</script>
<!--引入外部JS文件-->
<script src="js/test.js" type="text/javascript" charset="utf-8"></script>
</body>

Guess you like

Origin blog.csdn.net/weixin_49035356/article/details/110178272