今天我们开始前端js交互逻辑的功能;
什么是javascript?
javascript大家可以看作是前端html页面中用来编写逻辑的功能,它可以用来操作前端的html中的显示元素以及样式元素,是一门弱类型的编程语言!
javascript的使用方式
javascript有两种使用方式:1.我们可以直接写在html的<script type="text/javascript"></script>的标签中;2.我们可以在外部创建.js后缀的文件,并在html中使用 <script type="text/javascript" src=""></script>来进行引用。看下面的例子,我们用两种方式来调用alert提示功能:
html中:
<html>
<head>
<title>css</title>
</head>
<body>
</body>
<script type="text/javascript">
alert("我是html中的javascript");
</script>
</html>
外部.js文件:
文件夹结构:
index.html:
<html>
<head>
<title>css</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
</body>
<script type="text/javascript" src="./index.js">
</script>
</html>
index.js:
alert("我是外部引入的js文件");
注:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>这部分用来设置中文字体,否则会出现乱码的问题,meta标签还可以用来设置网站关键字,有利于seo优化。
本文暂时没有评论,来添加一个吧(●'◡'●)