<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<button onclick="document.getElementById('demo').innerHTML=Date()">The time is?</button>
<p id="demo"></p><div>
<p id="demo"></p>
<input id="numb">
<button type="button" onclick="myFunction1()">Submit</button>
<p id="demo"></p>
<p>請輸入介於1~100的數字</p>
<script>
function myFunction() {
var txt;
var person = prompt("Please enter your name:", "Tom");
if (person == null || person == "") {
txt = "User cancelled the prompt.";
} else {
txt = "Hello " + person + "! How are you today?";
}
document.getElementById("demo").innerHTML = txt;
}
function displayDate() {
document.getElementById("demo").innerHTML = Date();
}
function myFunction1() {
var x, text;
x = document.getElementById("numb").value;
if (isNaN(x) || x < 1 || x > 100) {
text = "Input not valid";
} else {
text = "Input OK";
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>