|
< /script >
<h3>Lesson 3: my first .js code:</h3> <h4>JavaScript Popup Boxes</h4> <button onclick="myFunction01()">myFunction01: alert</button> <br><br><button onclick="myFunction02()">myFunction02: alert multi-lines</button> <br><br><button onclick="myFunction03()">myFunction03: location</button> <br><br><button onclick="myFunction04()">myFunction04: confirm</button> <br><br><button onclick="myFunction05()">myFunction05: prompt</button> <p id="name"></p> <script type='text/javascript'> function myFunction01() { alert("myFunction01: Hello! I am an alert box!"); } function myFunction02() { alert("myFunction02:\n Hello! I am an alert box!"); } function myFunction03() { // a javascript way to go to a new URL address window.location = "http://www.w3schools.com/jsref/met_win_alert.asp"; } function myFunction04() { // a javascript way to go to a new URL address var r = confirm("Press a button"); if (r == true) { x = "You pressed OK!"; } else { x = "You pressed Cancel!"; } alert(x) } function myFunction05() { var person = prompt("Please enter your name , ie.", "Harry Potter"); if (person != null) { document.getElementById("name").innerHTML = "Hello " + person + "! How are you today?"; // OR alert("Hello " + person + "! How are you today?") } } </script>
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title> myHtml5 Template </title> <!-- file:///C:/Notepad++Portable/javascript-Ben/myHtml5-Template.html --> </head> <body> <!-- this is an html comment: html code goes here: --> <script type='text/javascript'> // this is a javascript comment: javascript code goes here: </script> </body> </html>