JavaScript in HTML
如果你没学过 html , 这里有一个简单的 tutorial。
JavaScript 在 HTML 有几种方法 ?
Between Script Tags
<!DOCTYPE HTML>
<html>
<body>
<p>Before the script...</p>
<script>
alert( 'Hello, world!' );
</script>
<p>...After the script.</p>
</body>
</html>
External Files
html/script.js
function Hello() {
alert("Hello, World");
}
hello.html
<!DOCTYPE html>
<html>
<head>
<title>Javascript External Script</title>
<script src="/html/script.js" type="text/javascript"/></script>
</head>
<body>
<input type="button" onclick="Hello();" name="ok" value="Click Me" />
</body>
</html>
你也可以 call 远在他方的 javascript -> lodash.js
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.2.0/lodash.js"></script>
Inline in the HTML
<input type="button" onclick="Hello();" name="ok" value="Click Me" />