Dom Programming (III)

Source: Internet
Author: User

Simple menu making, reference code:

varUL = document.getElementById ("Parent"); varLis = Ul.getelementsbytagname ("Li");  for(vari =0; i < lis.length; i++) {                varULS = Lis[i].getelementsbytagname ("ul"); if(Uls.length >0) {uls[0].style.display ="None"; } lis[i].onmouseover=function () {varULS = This. getElementsByTagName ("ul"); if(Uls.length >0) {uls[0].style.display ="";                }                }; Lis[i].onmouseout=function () {varULS = This. getElementsByTagName ("ul"); if(Uls.length >0) {uls[0].style.display ="None";            }                }; }

If you add onclick, onmousemove, and other event responses to the body, then if the page is not full, then "the last element in the body (No Limit)" section is unable to respond to the event, you must use code to listen for those events on document
The value of the top, left, width, height, etc. of an element is not a number, but a string such as "10px", which is used to set values for these properties, ie can be 80 or 90, and FF must be a string of "80px", "90%", etc. In order to be compatible with the uniform string form. Easy wrong: Do not write div1.style.width=80px, but div1.style.width= ' 80px '. If you want to modify the size of an element (width plus 10), first remove the width of the element, then convert the width to a number with parseint (parseint can parse the string containing other content starting with "20px" to 20,), and then add a value, plus the PX assignment back.
The position style value of the element: static (no positioning, displayed in the default position), absolute (absolute positioning), fixed (relative to the window's anchor, position does not change with the browser scrolling, IE6 not supported), Relative (position relative to the default position of the element). If you want to modify the coordinates of an element by code, you typically use absolute, and then modify the top (top edge distance) of the element, and the left (distance of the edge) two style values. Left and top are the coordinates of the upper-right corner of the layer. Word-break:break-all; Overflow:scroll

Img.style.top = event.clienty+ "px";
Img.style.left = event.clientx+ "px";

Two usages of createelement, pay attention to the problem of innertext
var input = document.createelement ("<input type= ' button ' value= ' Hello '/>") creates the element quickly and assigns a value, but note that the inner portion of the setting is not set to Var link = document.createelement ("<a href= ' http://www.baidu.com ' > Baidu </a>")
Label.setattribute ("for", "username");  Set some special properties for DOM element property names, Label.for = "username" will be problematic. Label.setattribute ("Xuehao", "33333")

document.getElementById (' btn1 '). Click ()
The Form object is the DOM object of the form. Method: Submit () submits the form, but does not trigger the onsubmit event. Implement Autopost, that is, the focus leaves the control after the page commits immediately, rather than only submit the submit button after the submission, when the cursor left to trigger the onblur event, in onblur call form's Submit method. After clicking Submit, the onsubmit event of the form is triggered, the data can be verified in the onsubmit, the data data is wrong, the return false can cancel the submission
<form name= "Form1" action= "a.aspx" method= "get" onsubmit= "if (document.getElementById (' txtname '). Value.length <=0) {alert (' name required '); return false;} " >

Pass parameters to the dialog box, pass parameters using the second argument of ShowModalDialog, Use Window.dialogarguments in the dialog box to get the passed parameter values, and the dialog box to set the return value for Window.parent.returnValue so that the return value of the setting can be read from the ShowModalDialog return value in the parent window. Passes multiple parameters, wraps the parameters into an array, and then passes through the second argument, returning multiple return values or returning an array

Methods for creating regular expression classes in javascript: var regex = new RegExp ("\\d{5}") or var regex =/\d{5}/
/Expression/is the syntax provided specifically for simplifying regular expression writing in JavaScript, and regular expressions written in//are not escaped by the Tube escape character.
Methods for RegExp objects:
(1) test (STR) determines whether the string str matches the regular expression, equivalent to IsMatch
var regex =/[email protected]+/;
Alert (Regex.test ("[email protected]");
Alert (Regex.test ("ab.com"));
(2) EXEC (str) search match, return value is match result, no return null (*)
The string object provides some methods related to regular expressions, equivalent to the wrapper for the RegExp class, which simplifies the call: Match (RegExp), which is equivalent to calling an exec
Keycode:ascii Code Description: 8: BACKSPACE. 46:delete. 37-40: Arrow key. 96-105: Number of keypad area. 48-57: Number of the main keyboard area. 110, 190: The decimal point for the keypad area and the main keyboard area. 189, 109: The minus sign for the keypad area and the main keyboard area. 13: Enter. 9:tab

Dom Programming (III)

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.