May 06, 2021 JavaScript
2. JavaScript is the scripting language
4. JavaScript: Write directly to the HTML output stream
5. JavaScript: Reaction to events
6. JavaScript: Change HTML content
7.. JavaScript: Change HTML images
9.. JavaScript: Change the HTML style
11.. JavaScript: Verify the input
JavaScript is the most popular scripting language on the Internet, which can be used for HTML and the web, and more widely for devices such as servers, PCs, laptops, tablets, and smartphones.
JavaScript is a lightweight programming language.
JavaScript is programmable code that can be inserted into HTML pages.
JavaScript can be executed by all modern browsers when it is inserted into an HTML page.
JavaScript is easy to learn.
Here are the main steps you'll learn in this tutorial.
You can only use document.write in HTML output. If you use this method after the document is loaded, the entire document is overwritten. |
The alert() function is not commonly used in JavaScript, but it is convenient for code testing.
The onclick event is just one of many events you'll learn about in this tutorial.
Using JavaScript to handle HTML content is a very powerful feature.
You'll often see document.getElementById ("some id"). ") This method is defined in HTML DOM.
DOM (D ocument O bject M odel) (document object model) is the official W3C standard for accessing HTML elements.
You'll learn about HTML DOM in several chapters of this tutorial.
This example dynamically changes the source (src) of html images:
The "light bulb" implementation code is detailed:
<script>
function changeImage()
{
element=document.getElementById('myimage')
if (element.src.match("bulbon"))
{
element.src="/images/pic_bulboff.gif";
}
else
{
element.src="/images/pic_bulbon.gif";
}
}
</script>
<img id="myimage" onclick="changeImage()" src="/images/pic_bulboff.gif" width="100" height="180">
In the above example, the code element.src.match ("bulbon") means:
Retrieving the value of the src property contains the bulbon string, if there is a string, the picture src is updated to
"changeImage()" src?/images/pic_bulboff.gif"width""100" bulb" height""180"
and
the value of the src property inside the bulbon, if there is a
string,
the picture src
is updated to
.gif,
and if the string is not matched,
the src
is updated
to bulbon.gif
JavaScript can change most properties of any HTML element, not just pictures.
Changing the style of an HTML element is a variant of changing HTML properties.
JavaScript is often used to validate the user's input.
The above examples are just ordinary validations, and if you want to use them in a production environment, you need to be strictly judged if you enter a space, or if a continuous space isNaN is not judged.
JavaScript and Java are two completely different languages, both conceptually and by design.
Java (invented by Sun) is a more complex programming language. ECMA-262 is the official name of the JavaScript standard. JavaScript was invented by Brendan Eich. It appeared in Netscape in 1995 (the browser stopped updating) and was adopted by ECMA, a standards association, in 1997. |
ECMAScript is a scripting language standardized by the European Association of Computer Manufacturers through ECMA-262.
JavaScript has been standardized by ECMA through ECMAScript.