The first touch with JavaScript

parent fc75859a
<html>
<body>
<h1>My First JavaScript</h1>
<button type="button">Click me to display Date and Time.</button>
<p id="demo"></p>
</body>
</html>
<html>
<body>
<h1>My First JavaScript</h1>
<button type="button" onClick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.
</button>
<p id="demo"></p>
</body>
</html>
<html>
<body>
<h1>JavaScript Can Change Images</h1>
<img id="myImage" onclick="changeImage()" src="13_pic_bulboff.gif" width="100px" height="180px" />
<p>Click the light bulb to turn on/off the light.</p>
<script type="text/javascript">
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "13_pic_bulboff.gif";
} else {
image.src = "13_pic_bulbon.gif";
}
}
</script>
</body>
</html>
<html>
<body>
<p>Please input a number between 1 and 10:</p>
<input id="numb" />
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("numb").value; /// Get the value of the input
if (isNaN(x) || x < 1 || x > 10) { /// If not Number or less than 1 or greater than 10
document.getElementById("demo").innerHTML = "Input not valid";
} else {
document.getElementById("demo").innerHTML = "Input OK";
}
}
</script>
</body>
</html>
<html>
<body>
<p>Please input a number between 1 and 10:</p>
<input id="numb" />
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
<script type="text/javascript" src="validate2.js"></script>
</body>
</html>
"use strict";
function myFunction() {
var x = document.getElementById("numb").value; /// Get the value of the input
if (isNaN(x) || x < 1 || x > 10) { /// If not Number or less than 1 or greater than 10
document.getElementById("demo").innerHTML = "Input not valid";
} else {
document.getElementById("demo").innerHTML = "Input OK";
}
console.log("Done.");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment