This article mainly introduces the JavaScript image library of reading notes in JavaScriptDOM programming Art. if you need it, you can refer to the following two methods to change the src attribute of the image:
1. the setAttribute method is an integral part of "level 1st DOM". it can be used to set any attribute of an element node.
2, element. src = source; this is the method before "level 1st DOM" appears, and it is valid now.
The advantage of "level 1st DOM" is its portability. old methods only apply to Web documents, and DOM applies to any markup language.
Event Processing Functions
When clicking a link, I want to stay on this page rather than go to another window. the code is as follows:
The code is as follows:
Click
When you click this link, because the value returned by the Javascript code triggered by the onclick event handler is false, the default behavior of this link is not triggered.
ChildNodes attributes
The childNodes attribute can be used to obtain all child elements of any element. The array returned by the childNodes attribute contains all types of nodes, not just element nodes. In fact, almost everything in the document is a node, and even space and line breaks are interpreted as nodes, all of which are included in the array returned by the childNodes attribute.
However, each node has the nodeType attribute. The nodeType attribute has a total of 12 optional values, but only three of them are useful: the nodeType attribute value of the element node is 1, and the nodeType attribute value of the attribute node is 2, the value of nodeType for a text node is 3.
To change the value of a text node, use the nodeValue attribute provided by DOM.
The array element childNodes [0] has a more intuitive and readable synonym, which can be written as firstChild; DOM also provides a corresponding lastChild attribute.
Example:
The code is as follows:
Choose an image
First, create a variable to store it:
The code is as follows:
Var description = document. getElementById ("description ");
The return value of description. nodeValue is null.
The nodeValue attribute of the element itself is a null value.
The value of the text contained in the element. use description. childNodes [0]. nodeValue or description. firstChild. nodeValue.