Wednesday, September 23, 2015
JavaScript on one page
The best way of combining JS examples from the tutorial on one page is creating special placeholders (like paragraphs with id) that can be referred in the script by these ids. You can use functions to structure examples or just JS operations for specific id, or mixing both. In the example below I am showing how to use a function with some calculation and just an expression assigned to the part of the document specified by an id (f.e using:
document.getElementById("demo").innerHTML )
<!DOCTYPE html>
<html>
<body>
<p>This example calls a function which performs a calculation, and returns the result:</p>
<p id="demo"></p>
<p>This example shows string concatenation:</p>
<p id="concat"></p>
<script>
function myFunction(a, b) {
return a * b;
}
document.getElementById("demo").innerHTML = myFunction(4, 3);
var carName1 = "Volvo XC60";
var carName2 = 'Volvo XC60';
document.getElementById("concat").innerHTML =
carName1 + " " + carName2;
</script>
</body>
</html>
You can copy the whole text and paste it in one of the w3schools examples (f.e
http://www.w3schools.com/js/tryit.asp?filename=tryjs_strings) substituting ALL their text with the one above.
You can do such trials by copying code into w3schools example, rearranging it and running.
After it works you can copy the whole page to your Ramapo server.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment