JavaScript support for traditional Document Object Models
This article briefly introduces the support of JavaScript For the object model of traditional documents. It is an important knowledge in JS learning. For more information, see
This is a model introduced in earlier versions of JavaScript. All are supported by all browsers, but only some key parts of the file can be accessed, such as forms, form elements and images.
This model provides several read-only attributes, such as the title, URL, and overall information about the document from the previous change. In addition to the methods that this model can be used to set and obtain document attribute values.
Document attributes are stored in the traditional DOM:
The following is the document attribute. You can use the traditional DOM access list:
Document methods in the traditional DOM:
Here is a list of methods supported by the traditional DOM:
Example:
We can find any HTML element and use html dom for any HTML document. For example, if a webpage file contains a form element and uses JavaScript, we can call it document. forms [0]. If a Web document contains two form elements, the first form is called document. forms [0] and the second is document. forms [1].
You can use document. forms [0]. elements [0] and so on by using the level and nature given above.
The following is an example of accessing the document attributes using the traditional DOM method:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<Html> <Head> <Title> Document Title </title> <Script type = "text/javascript"> <! -- Function myFunc () { Var ret = document. title; Alert ("Document Title:" + ret ); Var ret = document. URL; Alert ("Document URL:" + ret ); Var ret = document. forms [0]; Alert ("Document First Form:" + ret ); Var ret = document. forms [0]. elements [1]; Alert ("Second element:" + ret ); } // --> </Script> </Head> <Body> <H1 id = "title"> This is main title <P> Click the following to see the result: </p> <Form name = "FirstForm"> <Input type = "button" value = "Click Me" onclick = "myFunc ();"/> <Input type = "button" value = "Cancel"> </Form> <Form name = "SecondForm"> <Input type = "button" value = "Don't ClickMe"/> </Form> </Body> </Html> |
Note: For returned objects such as the form and content of this example, we will have to use the attributes of these objects not discussed in this tutorial to access their values.