如何插入js,引用外部js,js在页面中的位置
2021-04-08 14:26
阅读:695
标签:设置 添加 使用 运行 view 还需要 引入 code ref
我们来看看如何写入JS代码?你只需一步操作,使用之间。尤其注意的是之间的是文本类型(text),javascript是为了告诉浏览器里面的文本是属于JavaScript语言。
1 DOCTYPE html> 2 html> 3 head> 4 meta charset="utf-8"> 5 title>javascript插入页面title> 6 script type="text/javascript"> 7 document.write("hello javascript") 8 script> 9 head> 10 body> 11 body> 12 html>
JavaScript代码只能写在HTML文件中吗?当然不是,我们可以把HTML文件和JS代码分开,并单独创建一个JavaScript文件(简称JS文件),其文件后缀通常为.js,然后将JS代码直接写在JS文件中;在JS文件中,不需要,就可将JS文件嵌入HTML文件中。
1 DOCTYPE html> 2 html lang="zh"> 3 head> 4 meta charset="UTF-8"> 5 meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 meta http-equiv="X-UA-Compatible" content="ie=edge"> 7 title>javascript外部文件引入title> 8 script src="demo2.js" type="text/javascript" charset="utf-8">script> 9 head> 10 body> 11 body> 12 html>
插入得js文件书写
1 //书写js代码 2 document.write("我是demo2文件")
我们可以将JavaScript代码放在html文件中任何位置,但是我们一般放在网页的head或者body部分。
放在
如何插入js,引用外部js,js在页面中的位置
标签:设置 添加 使用 运行 view 还需要 引入 code ref
原文地址:https://www.cnblogs.com/dhnblog/p/12459842.html
下一篇:网页导出Pdf,样式不变
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:如何插入js,引用外部js,js在页面中的位置
文章链接:http://soscw.com/index.php/essay/72898.html
文章标题:如何插入js,引用外部js,js在页面中的位置
文章链接:http://soscw.com/index.php/essay/72898.html
评论
亲,登录后才可以留言!