JsDom programming Summary

Source: Internet
Author: User

1. browser compatibility issues:
Example of browser compatibility: ie6 and ie7 for table. appendChild ("tr") is supported differently from IE8. Use insertRow or insertCell to replace or add tbody to the table, and then add tr to the tbody. FF (FireFox) does not support InnerText, instead of textContent
2. Almost all DOM elements have the innerText and innerHTML attributes (case sensitive), which are the text representation of the content in the element tag and the HTML source code. These two attributes are readable and writable.
When creating elements dynamically, innerHTML can replace createElement (), which is simple and extensive and creates at your own risk.
3. write ():
Document. write () can be dynamically created only during page loading
4.
Document is an attribute of the window object. Because window can be omitted when a window object member is used, the document is generally written directly.
5. history operation history
Window. history. back (); window. history. forward () advances. You can also use window. history. go (-1) and window. history. go (1) to move forward.
6. clipboardData object:
ClearData ("Text") clears the clipboard. getData ("Text") reads the clipboard value. The returned value is the content in the clipboard. setData ("Text", val) sets the value in the clipboard.
7. oncopy = "setTimeout ('modifyclipboard () ', 100 )". After the user's copy operation takes 0.1 seconds, the content in the clipboard will be changed. 1000 ms is just a regular value, with 200, 10, 50 ...... Yes. You cannot directly modify the clipboard in oncopy. You cannot directly execute the clipboard operation in oncopy. Therefore, the timer is set to be executed after 0.1 seconds, so that the oncopy execution call stack is no longer available.
8. returnValue attributes:
If the returnValue attribute is set to false, the processing of the default event is canceled. In The onclick of the hyperlink, access to the href page is prohibited. During form verification, you are prohibited from submitting forms to the server. This prevents the submission of incorrect data to the server and page refreshing.
// Window. event. returnValue is not compatible with Firefox
9.
Window. event object member:
SrcElement to obtain the event source object. Several events share an event response function. * *** _ Click (object sender, EventArgs e) // only supports IE.
Button. when an event occurs, press the mouse key. The value 1 indicates the left button, the value 2 indicates the right button, and the value 3 indicates the left and right keys. // Test the value of event. button in the onmousedown event. If you can only recognize the left mouse click in The onclick event.
10.
Window. location. href = ''; // navigate to the new page. You can set a value or assign a value.
Window. location. reload (); // refresh the current page
Location. search: Get url (? After ?)
11.
(1) onload: triggered when the webpage is loaded. the browser downloads the document and parses and executes the file. Some elements need to be operated during JavaScript execution. This element has not been loaded yet, in this case, the operation code should be put into the onload event of the body, or JavaScript can be put after the element. The onload event of the element is triggered when the element is loaded, and the onload of the body is all loaded.
(2) onunload: triggered when the webpage is closed (or left.
(3) onbeforeunload: triggered before the webpage is ready to be closed (or left.
<Body onbeforeunload = "return" Do you really want to quit posting? '; ">. The displayed text varies with the browser version.
12.
When calling a method in js, the pointer is assigned to it.
Var t = add;
Function add (){}
13.
Window. event. clientX is the client visual interface.
14.
1. The setInterval (code, time) method can execute code once every time millisecond.
The code can be either of the following methods:
1. directly pass in a method object-setInterval (showTime, 1000 );
2. directly input the js Code string to be executed-setInterval ("alert (1);", 1000 );
2. for in (attributes and values used to loop objects)
When the for in clause is used to loop the array, the attributes of the array are first recycled.
Then we loop through the elements in the array, but the k in the loop is the subscript of the element.
Iii. innerHTML
Add the string to the middle of the corresponding double tag.
And parse the string immediately. If the syntax of the html Tag is met,
Then, immediately call the browser parser to parse the string in html, and
Generate the corresponding dom object. Finally, append the dom object to the added dom object.
The child element set of the object (ChildNodes.
15.
Functions of the ShowModalDialog function:
Open a Child window and pass data with the parent window. The biggest difference between it and window. open
It is because the parent window cannot be operated after the subwindow is opened by ShowModalDialog.
Usage:
VReturnValue = window. showModalDialog (sURL [, vArguments] [,
SFeatures])
Parameter description:
SURL
Required parameter. Type: string. Specifies the URL of the document to be displayed in the dialog box.
VArguments
Optional parameter; Type: variant. Used to pass parameters to the dialog box. Parameter types are not limited, including numbers
Group. The dialog box uses window. dialogArguments to obtain the passed parameters.
SFeatures
Optional parameter; Type: String. Used to describe the appearance and other information of the dialog box. You can use one of the following
Separated by semicolons.
DialogHeight dialog box height, not smaller than PX, IE4 dialogHeight
The default unit of dialogWidth and dialogWidth is em, while that of IE5 is px.
In px format.
DialogWidth: Dialog Box width.
DialogLeft: The left distance from the desktop.
DialogTop: the distance from the desktop.
Center: {yes | no | 1 | 0}: whether the window is centered. The default value is yes, but you can still specify
Height and width.
Help: {yes | no | 1 | 0}: whether to display the help button. The default value is yes.
Resizable: {yes | no | 1 | 0} [IE5 +]: whether the size can be changed. Mo
Recognize no.
Status: {yes | no | 1 | 0} [IE5 +]: whether to display the status bar. The default value is yes [
Modeless] or no [Modal].
Scroll: {yes | no | 1 | 0 | on | off}: indicates whether the dialog box shows scrolling.
. The default value is yes.
Parameter transfer method:
The parent window uses the ShowModalDialog parameter to pass to the Child window. The parent window needs to obtain
Parameters returned by the subwindow can be obtained through the return value of the ShowModalDialog function.
The method for obtaining the parent window parameters in the subwindow is to use the dialogArguments attribute of the subwindow window object to obtain
For example:
Parent.html
<Script>
Var obj = new Object ();
Obj. name = "51js ";
Window. showModalDialog
("Modal.html", obj, "dialogWidth = 200px; dialogHeight = 100px ");
</Script>
Modal.html
<Script>
Var obj = window. dialogArguments
Alert ("the parameter you passed is:" + obj. name)
</Script>
The window. returnValue attribute is used in the Child window to return parameters to the parent window, for example:
Window. returnValue = 1;
Window. close ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.