在html中可以写js代码,script标签的作用就是于定义客户端脚本,设置标签属性type的值为“text/javascript”即可,语法为“<script type="text/javascript">js代码</script>”。

实例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob)</title>
<script>
function displayDate(){
	document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>

<h1>我的第一个 JavaScript 程序</h1>
<p id="demo">这是一个段落</p>

<button type="button" onclick="displayDate()">显示日期</button>

</body>
</html>

运行效果

更多推荐

HTML里写JS