Home > front end >  JavaScript object is commonly used methods and properties of the nodule
JavaScript object is commonly used methods and properties of the nodule

Time:10-12

Method a, list
JavaScript has powerful processing capabilities, with this method, to write out rich and colorful web page, in this part, we will introduce how to use the methods and properties related to the string object,
1. The length of string object attribute
Only one string object attribute length, the attribute value indicates the included character string relative Numbers, grammar is: stringName. Length
2. The list of object method
JavaScript provides multiple ways to help control display information, string methods can be divided into several categories, such as the method of attribute, the navigation method, etc., below we will introduce classification,
Method (1) the method of attribute specifies the common way of text displayed on the screen, it provides an ideal way to make the page more attractive,
Blink blink () () method causes the text, grammar form is as follows: string. Blink ();
Bold bold () () method to make string to bold, syntactic form is as follows: string. The bold ();
Fontcolor fontcolor () () method can change the color of a single string, or every time to reload the page or event occurs, change color, also, this method also has a corresponding HTML logo - fontcolor () syntax is a string. The fontcolor (color); Here, the color is a kind of color legal said,
Italics italics () () method of the string of italic, to distinguish with the rest of the text, italics () syntax is as follows: string. Italics ();
(2) the case method JavaScript strictly distinguish between the letter case, in order to easily compare two strings, will put them all into uppercase or lowercase, string object the case method of conversion between support in the case,
ToLowerCase () toLowerCase () method to each character in a given string into a small state, syntactic form is as follows: string=stringValue. ToLowerCase ();
ToUpperCase () and tolowerCase () method is opposite toUpperCase () method, which transform a given string into uppercase string, the string=stringValue. The toUpperCase ();
(3) the operation method of operation method offers many kind within a text string to find the method of the string, including the charAt (), indexO f (), LastIndexOf () and the substring () four methods, we can use these methods to format and operation of user input string variables, including charAt () and the substring () two methods drawn from a string of one or more characters, the remaining two method returns for the lookup value appear in the position of the first character in a string of digital values,
CharAt () charAt () method returns from a given string specify the location of the characters, its usage is as follows: string. The charAt (index); One index is a number between 0 and is less than the string Length (string Length can be obtained by Length attribute),
The substring () the substring () method returns it from a large bunch of a substring, its syntactic form is as follows: the string. The substring (indexA, indexB) indexA and indexB both numeric values between 0 and string length, they are a bunch of two subscripts,
IndexOf () indexOf () method returns the specified string in a long list of the location of the matching substring, it from left to right to search for a given string, syntactic form is as follows: string. The indexOf (searchValue, [fromIndex]); One string is indexOf () in which to find searchValue string, and searc hValue is any character or want to find the substring, fromIndex is an option, it specifies the search start position, fromIndex scope and charAt () and Subs tring () like (0 to length - 1), it can't be greater than or equal to the length, if you don't specify fromIndex, this method is that by default? And find the whole bunch, indexOf () of the return value is the offset of the first character of the first occurrence searchValue (from the beginning of the string), even specifies fromIndex, the return value is relative to the beginning of the string (probably in some place in front of the se archValue will be ignored),
LastIndexOf () lastIndexOf () method and the IndexOf () method is similar, except that it from right to left to find the string, lastIndexOf () are still is to find the list of the first character position, rather than at the end of the position of the character, the lastIndexOf () method of syntactic form is as follows: string. The Last IndexOf (searchValue); SearchValue is still want to find the string,
(4) use hypertext navigation method when they come into contact with the anchor (anchor) and the concept of link, the anchor as the label is placed in web page (you can easily return to there); Link to another page (or anchor) of the same and different page, the guidance of the
Anchor () an () method is used to set an anchor, its syntactic form is very simple: string. The anchor (anchorName); Examine the following examples: var indexString="Index". Document. Writeln (indexString. Anchor (" anchorName ")); This statement on the screen print text Index; AnchorName is this anchor real name, like this anchor is generally used to link to jump to anchor the actual location of the page,
Link link () () function is to jump to the specified target, it is equal to the reference standard HTML (hypertext reference) designated by the HREF attribute, its syntactic form also is very simple: linkText. Link (HREF) linkText is the text on the screen, the HREF attribute is not necessarily an anchor, it also can be a legitimate URL references, the following example shows how to use the link () to create jump straight to the front to create the anchor link; Var indexStirng="Index" document. Writeln (indexString. Link (" # "+" anchorName ") + "") the statement on the screen print link format text Index (usually underlined below); AnchorName is the actual name of anchor, when click on this link, the anchor at the top of the window will appear in the browser users, please note: to ensure that the same document inside the anchor in the reference and # #, # # on time, will be enclosed in double quotation marks it with a plus sign it up with a complete reference, you can see the previous example, if you omit the # #, link's aim is to a file instead of an anchor, click on the chain will make the browser attempts to load is called anchorName files (in this case), because the file does not exist, the browser will produce Notfound errors information,
Second, window method
Browser window is interact with the user interface, using the methods and properties window in the JavaScript, you can create a console window, in this part, introduces some methods and properties window,
1. The predefined window (dialog)
JavaScript provides three methods to produce the "simple" window or dialog box: alert (), confirm and promp t () (), although we can't control the position of the dialog box, a button or the size, but they offer a preliminary mechanism to prompt the user or receive input, the following discussion of each method,
Alert () alert () method to set up a separate message window, syntactic form is as follows: alert (" message ") is the "message" to the prompt window display a text string,
Confirm confirm () () method is used to perform an event before the request for the user's recognition, it appears to the user to stop an event of chance, syntactic form of the method is as follows: confirm (" message ") in which the message is a text string,
Prompt prompt () () method receives the user's feedback, the user can from the keyboard typing information, or if they receive a default value, you can use the mouse to select the syntactic form of the method is as follows: prompt (" message ") if you want to specify a default value, can use the: prompt (" message ", imputDefault) the "message" is a text or Numbers, the user can enter any information, therefore, a variable although hope to enter a numeric calculation, may also is the text input to it, if you click the Cancel button and close button and pr ompt () returns null,
2. Custom window
Although the above three kinds of window is very simple, but they have a common drawback is not flexible, that can change their size and style, here, let's discuss the problem of how to customize the window in the JavaScript, first of all, we should know how to create a window,
Open () the open () method creates a New window, use this method to create a window and select the File menu item New Web Bro wser is similar, the effect of syntactic form of the method is as follows: windowVar.=Windows open (" URL ", "windowName") or you can define a window attributes: windowVar=window. The open (" URL ", "windowName", "windowAttribut er") which the windowName is to create the name of the window, the URL is a text string that specifies the New window is created to invoke the URL, if you don't specify a URL (to use an empty string ""), then the window is empty, windowName represents the name of the window, windowFeatures optional attributes can be assigned to the window, such as a toolbar, location, catalog, the status bar, menu bar, the scroll bar, the ability of variable size, width and height (see table), setting them by commas as the delimiter, and add double quotation marks at the outside,
Window properties form the use of these properties are as follows: feeture=value which the feature is to select attributes, the value (in addition to the width and height of two attributes) or yes (or 1) to activate the property, or no (or zero) to eliminate it, width and height of grammatical form is as follows: feature=pixels pixels is any positive integer) (or a positive integer variables, determine the size of the new window (in pixels),
Close () using the close () method, its syntactic form is as follows: windowReference. Close () can be used with any of the following functions: close the current window window. Close (), the self. The close (), close (), we can quote a window windowVar (this value is called open () method to produce), to shut down a separate window, such as: the command is used when creating a window: WindowB=open (", ", "anotherwindow", "windth=80, height=40); We can close it in any other window, using the command: windowB. Close close () the top window top. Can use the following method close (), of course, if you want to close the current window, we can use any shutdown command by oneself,

Javascript provides us with some very useful common internal object and method, the user does not need to use script to implement these functions, which is based on the real purpose of object programming,
In javascript provides string (string), math (numerical) and Date (Date) three types of objects, and other related methods, thus for programmers to rapidly develop powerful script provides a very favorable condition,

1, commonly used internal objects
In javascript for reference object properties and methods, there are two situations: one is that the objects are static objects, in reference to the object's properties or methods do not need to create an instance for it; While another object in the object or method of reference it is necessary for it to create an instance of the dynamic object, the object is
For internal javascript object references, is tightly around its attributes and methods, thus clear the object's static and dynamic sex to grasp and understand the internal javascript object is of very important significance,

1), string objects
O string object: internal static,
O access the properties and the methods, the implementation can use (.) operator,
Basic format: o the objectName. Prop/the methods
(1) the attributes of the object string
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related