JS Notes-02

Source: Internet
Author: User
Tags tag name

1.String intercept: substr: Cut a few, substring: cut to where.

2.String operations, such as capitalization, lowercase, do not change by themselves, just exchange references in the stack
var str = "Hello world";
var STR5 = Str.touppercase ();
document.write (STR5);
Str doesn't change, it loses STR5.

3.String replacement (/Regular expression (fixed expression)/, "destination string");
STR (/mama/g, "Baba"); change all mama to Baba (g: All)

4. If you first run script in head (document.write (""))
Script, then, the contents of the body will be overwritten
Summary: The page does not have a tag element and can have write (); There is no, otherwise overwrite

5. Dynamic time Display error problem: A. Global variable problem st B.settimeout:o to lowercase.

Run only once: var s = setTimeout ("function", number of milliseconds);
Clear: cleartimeout (s)
Run multiple times: var s = setinterval ("function", number of milliseconds);
Clear: clearinterval (s)

6.window objects
A. The open () method and the <a href = "" > can open a new window,
Different: Open (you can set properties of the window), but hyperlinks are not.
B.window.location = "" (Location.href = "")
C. window.showModalDialog ("js03.html"): You can also open a
New window, but this window must be handled, otherwise it won't move

D.window.onload (function name ()): The function is to put all the pages of the explanation finished before running the program.

History.go (-1): Fallback page
History.go (1): Forward page.
From page A to page B, forward to the event on page A, back on page b
, first click on a to B connection, then two forward back buttons are activated

8. Get a set of values by tag name
getElementById (id value);
Getelementsbyname ("Name value");
Getelementbytagname (standard signature);
Select as: Checked property to

tagname Example: Iterating through the array using the list <li> tags; note: use (object.innerhtml) when taking values
All tags without value are used with the innerHTML property

9. The purpose is: let the page things loaded, and then execute the JS code, in case the page things are overwritten.
Common: Window.onload = function () {
JS Code}

Infrequently used: function name () {} <body onload = "name ()" >

Security: window.onload = function () {
Gets the object of the button. onclick = function () {
The operation performed;

JS Notes-02

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.