Client programming-JavaScript (4)

Source: Internet
Author: User

Javascript event processing

Bind events to elements:
<Form onsubmit = "myfunction ();">
Use the script to associate the handler with an object. Document. getelementbyid ("myform"). onsubmit = myfunction;
Use patented methods such as IE's attachevent ()
Use the dom2 method to set the event listener with a node Huang addeventlistener ()

How to trigger an event:
The browser responds to some initial behaviors of the user or Javascript by implicitly triggering. <body onload () = "myfunction ();">
Use the dom1 method in JavaScript to display trigger. Document. Forms [0]. Submit ()
Use patented methods such as IE fireevent ()
Use the dispatchevent () method of dom2 in JavaScript to display the trigger

Event Handler attributes of basic events and elements corresponding to XHTML
When onblur loses focus, onchange loses focus and the value of onclick ondblclick is modified.
Onfocus obtains the focus ondeydown. when the focus is on an element, the onkeypres onkeyup key is pressed.
Onload onmousedown onmosemove onmouseout onmouseover the mouse has been moved to an element onmouseup
Onrest indicates that the form is being reset. onselect indicates that a text onsubmit onUnload is selected.

Binding in Javascript is more efficient than binding in XHTML attributes when you want to dynamically add or delete a processing program. This helps improve the separation of the document structure, logic, and representation.

Modern event model
A major difference between the modern event model and the basic event model is the addition of the event object, which provides a context snapshot for each event processing program when an event occurs.

E bind the event handler to the object: attachevent ("event to be processed", Handler) detachevent ("event to be processed", Handler)

Dom2 event model
The event in dom2 starts its lifecycle at the top of the object hierarchy (document), then drops along the contained object, reaches the target, executes the processing program, and then the event bubbles up to the top.

You can use addeventlistener () to bind an event. You can bind multiple handlers to the same event. 2. Process event 3 when the event falls to the target, this method can bind the handler to a text node.
Object. addeventlistener ("Event", handler, capturephase) the object is the node event bound to the listener. The event is a string indicating the event to be monitored. handler is used when an event occurs, the function capturephase to be called is a Boolean value of true to decrease flase bubble.

Prevent default behavior preventdefault () Prevent event propagation stoppropagation ()

 

Javascript browser control window

Dialog Box alert (string) confirmation dialog box boolea confirm (string) Prompt dialog box string prompt (prompt string, default string)

Open and Close a normal window. OPTN (URL, name, features, replace) name is the window name. feature is a comma-separated feature list of windows. Replace is a boolea that indicates whether the specified URL replaces the window content.

Features loop parameter value
Alwayslowered indicates whether the window is placed behind all other windows
Alwaysraised indicates whether the window is placed on all other windows.
Whether fullscreen is full screen display (IE)
Hotkeys indicates whether the browser's hotkey overwrites the basic hotkey.
Resizable specifies whether the user can zoom the window
Scrollbars indicates whether a scroll bar is displayed.
Directories specifies whether to display the address button
Status specifies whether to display the status bar
Titlebar specifies whether to display the title bar
Toolbar specifies whether to display the toolbar
Location specifies whether to display the address bar
Menubar: Specify whether to display menu bar
Innerheight: sets the internal height of the window displayed by the user document.
Innerwidth... width
Outerheight: Set the external height of the window.
Outerwidth: Set the external width of the window.
Left form's position relative to the left side of the screen (IE)
Position of the top form relative to the top of the screen (IE)
Position of the screenx form relative to the left side of the screen (Netscape)
Screeny form ............
Height window height
Width window width

Write document. Write () into the window and write document. Close ();
Moving a window relative to moving window. moveBy (horizontal Prime, vertical prime) Absolutely moves windowname. moveTo (x, y)
Adjust the window size relative to woindow. resizeBy (). Absolutely adjust window. resizeTo ()
Relative scrolling window. scrollby () Absolute scrolling window. scrillto ()
Set window address window. Location = "http ://..."
History of the access window history. Forward () Forward history. Back () backward history. Go (I) forward and backward
The status bar status in the control window is set to the information temporarily displayed in the status bar defaultstatus default status bar text information
Set window timeout and interval setTimeout (fun, time) set a script cleartimeout () that runs after the specified time ()

Common window events
Onblur window loses focus
Triggered when an onerror JavaScript error occurs
Onfocus window obtains focus
Onload
Onresize triggered when the user adjusts the window size
OnUnload triggered when document is uninstalled

Window. showmodaldialog in IE mode (URL, parameters, and features of the dialog box)

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.