Two ways to change the src attribute of a picture:
The 1,setattribute method is part of the "level 1th dom", which can set any property of an element node.
2,ELEMENT.SRC = Source; This is the way before "level 1th dom" appears, and it is now valid.
The advantage of "level 1th dom" is portability, and those old methods apply only to Web documents, and DOM applies to any markup language.
Event handler function
When I click on a link, I want to stay on this page rather than go to another window, the code is as follows:
Copy Code code as follows:
<a href= "http://www.example.com" onclick= "Showpic" (this); return false; >Click</a>
When this link is clicked, the default behavior of this link is not triggered because the JavaScript code that is triggered by the OnClick event handler returns a false value.
ChildNodes Property
The ChildNodes property can be used to get all the child elements of any one element. The array returned by the ChildNodes property contains all types of nodes, not just element nodes. In fact, almost everything in the document is a node, and even spaces and line breaks are interpreted as nodes, all of which are contained in the array returned by the ChildNodes property.
However, each node has a NodeType attribute. The NodeType attribute has a total of 12 desirable values, but only 3 of them have value: the NodeType property value of the element node is 1, the NodeType property value of the attribute node is 2, and the NodeType property value of the text node is 3.
If you want to change the value of a text node, use the NodeValue attribute provided by the DOM.
Array element Childnodes[0] has a more intuitive and readable synonym that can be written as Firstchild;dom and provides a corresponding LastChild attribute.
Example:
Copy Code code as follows:
<p id= "description" >choose an image</p>
First create a variable to store it:
Copy Code code as follows:
var description = document.getElementById ("description");
The return value of the description.nodevalue is null. The NodeValue property of the <p> element itself is a null value, and if you want to get the value of the text contained in the <p> element, use Description.childnodes[0]. NodeValue or Description.firstChild.nodeValue.