What is a JavaScript?
JavaScript is an interpreted scripting language that can be inserted into an HTML page and interpreted by the browser.
What can two JavaScript do?
① adding new content to HTML
document.write ("
document.write ("<p>this is a paragraph</p>");
Note: Use document.write during HTML output instead of using this method after the document is loaded, otherwise it will overwrite the entire document.
② Response to Events
<button type= "button" onclick= "alert (' welcome! ')" > Click here </button>
The alert () function is often used for code testing, displaying content and judging whether it is expected.
③ changing HTML content
You can use document.getElementById to get to an HTML element and modify its contents to change the HTML content
X=document.getelementbyid ("demo")//Find elements
X.innerhtml= "Hello JavaScript"; Change Content
④ changing HTML images
You can use document.getElementById (' myimage ') to get a picture element and re-assign a value to the path to the element
element.src= New Path
⑤ changing the style of HTML elements
Changing the style of HTML elements is a variant of changing HTML attributes.
X=document.getelementbyid ("demo")//Find element
X.style.color= "#ff0000";
Validate input
JavaScript is often used to validate user input.
Instance
If IsNaN (x) {alert ("Not Numeric")};
JavaScript Learning notes a JavaScript what can do