基础 JavaScript 实例

本文介绍了JavaScript在HTML中的多种使用方式,包括直接在HTML文件中编写、利用`document.write()`输出文本及HTML元素、通过外部JavaScript文件引入脚本、以及如何在页面加载时触发特定的JavaScript函数。
生成文本
<html>
<body>

<script type="text/javascript">
document.write("Hello World!")
</script>

</body>
</html>

生成普通文本和标签  
<html>
<body>

<script type="text/javascript">
document.write("<h1>Hello World!</h1>")
</script>

</body>
</html>

head 部分
<html>
<head>
<script type="text/javascript">
function message()
{
alert("该提示框是通过 onload 事件调用的。")
}
</script>
</head>

<body onload="message()">

</body>
</html>

body 部分
<html>
<head>
</head>

<body>

<script type="text/javascript">
document.write("该消息在页面加载时输出。")
</script>

</body>
</html>

外部 JavaScript
<html>
<head>
</head>
<body>

<script src="../js/example_externaljs.js" tppabs="http://www.w3school.com.cn/js/example_externaljs.js">
</script>

<p>
实际的脚本位于名为 "xxx.js" 的外部脚本中。
</p>

</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值