网站推广.NET

网站推广.NET

html怎么和js连接

来源:互联网

本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。

js和HTML结合(连接)有两种方式

靠前种:直接将js代码嵌入script标签对中

语法

立即学习“前端免费学习笔记(深入)”;

<script type="text/javascript"> js代码; </script>

第二种:使用script标签,引入一个外部js文件

*** 创建一个js文件,写js代码

***然后使用以下语句引入

<script type="text/javascript" src="js文件路径"></script>

使用第二种方式的时候,就不要在script标签里面写js代码了,不会执行。

示例:

<html>    <head>        <title>World</title>        <style type="text/css">        </style>    </head>    <body>        <script type="text/javascript">            alert("aaaaaa");        </script>    </body></html>
<html>    <head>        <title>World</title>        <style type="text/css">        </style>    </head>    <body>        <script type="text/javascript" src="1.js">            //alert("bbbbb");  没有效果        </script>    </body></html>

【相关推荐:javascript学习教程

标签: html js