目录
hello,world
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello,world</title>
</head>
<body>
<div>
<p>你好,世界</p>
</div>
</body>
</html>
打招呼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello,world</title>
</head>
<body>
<div>
<p>你好,我是waterperl!</p>
<p>
<label>如何称呼您?<br>您叫:<input type="text" id="username" /> </label>
<button onclick="showWelcome()">很高兴认识你</button>
</p>
</div>
<script type="text/javascript">
function showWelcome(){
let username = document.getElementById("username").value;
alert("你好,"+username);
}
</script>
</body>
</html>
当前日期
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello,world</title>
</head>
<body>
<hgroup>
<p>你好,我是waterperl!</p>
<p id="nowdate"></p>
</hgroup>
<script type="text/javascript">
let nowdate =document.getElementById('nowdate');
nowdate.innerHTML =Date();
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>hello,world</title>
</head>
<body>
<hgroup>
<p>你好,我是waterperl!</p>
<p id="nowdate"></p>
</hgroup>
<script type="text/javascript">
let nowdate =document.getElementById('nowdate');
let showDate=new Date(Date());
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
nowdate.innerHTML = "toLocaleString:"+showDate.toLocaleString({ timeZone: 'UTC' });
nowdate.innerHTML += "<br>toString:"+showDate.toString();
nowdate.innerHTML += "<br>toLocaleDateString:"+showDate.toLocaleDateString(undefined, options);
nowdate.innerHTML += "<br>toLocaleTimeString:"+showDate.toLocaleTimeString(undefined, options);
nowdate.innerHTML += "<br>toTimeString():"+showDate.toTimeString();
nowdate.innerHTML += "<br>toUTCString():"+showDate.toUTCString();
nowdate.innerHTML += "<br>toISOtring():"+showDate.toISOString();
</script>
</body>
</html>
toISOString() 方法返回一个 ISO(ISO 8601 Extended Format)格式的字符串: YYYY-MM-DDTHH:mm:ss.sssZ。时区总是 UTC(协调世界时),加一个后缀“Z”标识。