JavaScript Basics 06

Source: Internet
Author: User

JavaScript Basics 06

Splice

var Del_arr = Del.splice (0,2); Removes the specified number of DeleteCount elements from the specified position deletepos, returning the removed element as an array
The splice method has the function of adding, removing, replacing, It has three parameters, the first one is the position, the second is the number of deletions, and the third is the added thing.

String Object

The String object is used to manipulate text. In fact, any string constant is a string object that can be used directly as an object.

Get string Length: length

Extract String:

CharAt () This is to get a single character.

substr () intercept from the starting position, the second parameter is the length of the Intercept

Substring () intercept from the start position, the second parameter is the end position, but does not include this position, it cannot accept negative numbers

Slice () is the same as above, but can accept negative numbers

To find the replacement string:

IndexOf () Gets the position of the first occurrence of the specified string, and the second parameter is the start of the fetch Position.

LastIndex () Gets the location of the last occurrence of the specified string

Replace () replaces the local string, the first parameter is replaced, the second is replaced, and it is useful in the regular

Search () finds the specified string and returns back, as in the regular.

Other methods:

toLowerCase () turns into lowercase letters

Ouppercase () turn into uppercase

Window object

System message box alert ()

Confirmation dialog box Confirm ()

Input dialog box prompt ()

Open a new window window.open ()

window.open ("http://www.baidu.com", "_blank", "width=300, height=200");

Timer Setinterva (), setTimeout ():

Timers can be said to be the most common JS front-end tools, almost all the gradual change of dynamic effects will be used to the timer,

For example, the picture scrolling, gradually fade out, drag and so on. the timer is divided into two types: settimeout and Setinterval.

Attention:

one, the timer in the event or will appear multiple times to execute this timer, be sure to clear the timer, not the timer will be superimposed and appear timer in the acceleration of the same phenomenon or weird

things, This is the problem of timer overlay, if the timer superimposed, mend is not good, will find out how can not clear, so be sure to clear the timer before the execution,

Because the way to clear the timer, even if nothing can be cleared, it will not error, because this we do not have to be afraid to clear empty variables will be error, so bold clear.

second, this and the timer, this in the timer, it will point to the window, this problem, must know, not later will be this problem to be afraid to use this,this is the context of the environment,

This context is the environment in which the execution environment will be affected, generally the scope of the parent scope, but there are always some exceptions such as timers, wherever you use it

It's all pointing to window, why? It was written and suddenly understood ...

Because Window.setinterval () .... Do you understand me? Its superior execution Environment is window AH ah ah ah ah ah ...

If you do not understand what is the execution environment, what is the scope, see JavaScript Advanced Program design, which has detailed instructions: the third edition of the fourth chapter 4.2

History Object

The history object is a child of the window object, corresponding to the Browser's historical Record.

Window.history.go ( -1); window.history.go (1); history.back (); history.forward ();    

Location Object

The Location object is also a child of the window object, which allows you to get or set the current address of the Browser.

1. Jump to another page window.location.href = "http://www.163.com"; location.href = "http://www.163.com"; 2. Reload page (refresh) Location.reload ();

Navigator Object

The Navigator object contains information about the Web browser, which is also a property of the window, can be referenced with window.navigator, or it can be used with the Navigator reference example: get the browser internal code, name, operating system and other information var info = Navigator.useragent;alert (info);

IE8 the following version to Determine:

/*ie version get start */var default_version = "8.0"; var ua = Navigator.userAgent.toLowerCase (); var isie = ua.indexof ("msie") >-1; var safariversion;if (isie) {    safariversion =  ua.match (/msie ([\d.] +)/) [1];    If (safariversion <= default_version) {        alert (safariversion);    }} /*ie version get End */

Version gets to do a lot of things, such as compatibility, we can change a set of style sheet to show a compatible version of the page below ie8, which is like Media queries.

The following is a mind map of their own, people lazy do not want to Write.

Selector is so much now, if you want to fine-grained, there is a table-specific selector, form professional Selector.

Ways to manipulate Tables:

THead: Head

Tbodies: body

TFoot: Tail

Rows: rows

Cells: columns


such as otab.tbodies[0].rows[1].cells[1].innerhtml

This is the first TABLE element that gets to the form, and then uses the above action to get but the required Element.

Form Action:

The name value inside the form tag is important, which is more important than the ID.

He can get the name value directly, get the Document object

Obj.name

such as <form id= "from" ><input type= "text" name= "text1" ></form>var Ofrom=document.getelementbyid (' from ' ); var otext=ofrom.text1;

Note the high energy ahead:

In many aspects of the test, found that most of these selectors can not be dynamically acquired, is not this element to get it, the browser will error, and only document.getElementsByTagName () can

To do this, it is necessary to obtain the dynamic, or the tag Selector is Better.

The following is the test code:

<! DOCTYPE html>

Per day Push:

A word Porter today.

<! DOCTYPE Html>

JavaScript Basics 06

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.