如何引用JavaScript

2018-02-10  本文已影响0人  YANGXIAOFEI

内部引用

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

外部引用

< ! DOCTYPE html >
< html >
< head >
< script type = " text/javascript " src = " Hello.js " >< /script >
< /head >
< /html >

hello_01.html

< ! DOCTYPE html >
< html >
< head >
< meta charset = "UTF-8" >
< title > 外部脚本的使用 < /title >
< script src = " hello_01.js " >< /script >
< /head >
< /body >
< /h1 id = " helloMessage " > < /h1 >
< /body >
< /html >

hello_01.js

// JavaScript Document
window.onload = writeMessage;
function writeMessage(){
document.getElementById("helloMessage").innerHTML = "Hello, World!";
}

上一篇下一篇

猜你喜欢

热点阅读