HTML基础教程(十七)头部元素之<script>元素:<script>,让HTML“动”起来的魔法卷轴!

引言:当HTML遇见JavaScript——一场“动静结合”的包办婚姻

在Web世界的早期,HTML是一位安静沉稳的“文书工作者”,只负责规规矩矩地搭建文档结构。直到1995年,一位名叫Brendan Eich的“魔法师”在短短十天内创造了JavaScript,从此<script>元素如同一位调皮捣蛋的魔法学徒,让静态页面学会了“跳舞”——尽管最初它常因阻塞渲染而被吐槽为“页面加载的猪队友”!

如今,<script>已成长为Web开发的“瑞士军刀”,从简单的表单验证到复杂的单页应用,无一不是它的舞台。但你真的了解这位老朋友吗?本文将带你用“显微镜”观察<script>的每一个毛孔,顺便用实战代码揭晓如何让它从“拖后腿”变成“神助攻”!

一、基础回顾:<script>元素的“出厂设置”

1.1 基本语法与属性

<script>元素最直接的用法是内联代码或引用外部文件:

<!-- 内联脚本 -->
<script>
  alert('Hello from the 90s!');
</script>

<!-- 外部脚本 -->
<script src="app.js"></script>

但看似简单的标签背后隐藏着关键属性:

  • src:指定外部脚本URL(告别代码臃肿!)
  • type:早期用于标识语言类型(如text/javascript),如今更多用于模块脚本(module
  • defer/async:加载控制“双子星”(后续详解)
  • crossorigin:跨域请求配置(应对CORS限制)
  • integrity:子资源完整性校验(防范CDN被篡改)

1.2 类型演变:从MIME类型到模块化

历史上,type属性曾被迫标注复杂的MIME类型(如text/javascript;version=1.8),但现代浏览器已统一将JavaScript作为默认语言。真正的转折点是ES6模块的引入:

<script type="module">
  import { utils } from './utils.js';
  // 模块代码享有自己的作用域,自动启
<?xml version="1.0"?> <gameList> <game> <path>./01 - Get ES Themes.sh</path> <name>01 - Get ES Themes</name> <desc>Script used to install themes in Emuelec, themes downloaded from its original repository and installed in the Emuelec themes folder.</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/Get ES Themes.png</image> </game> <game> <path>./02 - File Manager (kb).sh</path> <name>02 - File Manager</name> <desc>MC File Manager. A keyboard is required!</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/File Manager.png</image> </game> <game> <path>./03 - wifi.sh</path> <name>03 - wifi</name> <desc>Connect to WiFi using wifi.txt in /storage/.config/wifi.txt</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/wifi.png</image> </game> <game> <path>./04 - Configure Reicast.sh</path> <name>04 - Configure Reicast</name> <desc>A simple script to configure reicast gamepad, a keyboard is required!</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/reicast.png</image> </game> <game> <path>./05 - install drastic.sh</path> <name>05 - install drastic</name> <desc>Download and install Drastic, internet is required!</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/drastic.png</image> </game> <game> <path>./07 - Skyscraper.sh</path> <name>07 - Skyscraper</name> <desc>Alternative ROM Scraper. Configuration is required!</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/sh.png</image> </game> <game> <path>./08 - send logs.sh</path> <name>08 - send logs</name> <desc>Use this to get a URL that you can share when asking for help</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/logs.png</image> </game> <game> <path>./09 - system info.sh</path> <name>09 - system info</name> <desc>Display System info</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/info.png</image> </game> <game> <path>./10 - Force Update.sh</path> <name>10 - Force Update</name> <desc>THIS IS OBSOLETE, USE THE DANGER ZONE "Reset scripts and binaries to default"</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/update.png</image> </game> <game> <path>./11 - Copy USB roms to device.sh</path> <name>11 - Copy USB roms to device</name> <desc>Easily copy ROMS from any external device to the SD/MMC where EmuELEC is installed</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/usb.png</image> </game> <game> <path>./12 - Show last emuelec.log.sh</path> <name>12 - Show last emuelec</name> <desc>Display the last emuelec.log on screen to debug game launching problems</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/last.png</image> </game> <game> <path>./13 - Launch Terminal (kb).sh</path> <name>13 - Launch Terminal</name> <desc>Start a terminal, a keybord is required!</desc> <developer>shantigilbert </developer> <publisher>Emuelec</publisher> <genre>script</genre> <image>./downloaded_images/terminal.png</image> </game> </gameList> 这个 gameList.list 是干嘛的
05-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

值引力

持续创作,多谢支持!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值