Common knowledge points in the development of JavaScript

Source: Internet
Author: User

Objective

Recently in the project when I wrote some javascipt code, so I made a simple look at the data collated, found the following several more useful knowledge points:

1, three ways to declare a function

2. JQuery $ (document). The difference between ready () and Window.onload

3, Location.href

4, get the parameters in the URL

5, to determine whether there is a function of the method

6, set the height of the IFRAME

7, the resolution text box settings read-only press the Back button back page

1, three ways to declare a function

1, declarative functions

function functionname (arg1, arg2) {alert (ARG1+ARG2);}

2. anonymous function

var functionName1 = new Function ("Arg1", "arg2", "alert (arg1 + arg2)");

3. Direct Measure function

FunctionName2 = function (Arg1, arg2) {alert (arg1 + arg2);

Three ways to call functions

functionname ("1", "22");

FunctionName1 ("2", "11");

FunctionName2 ("Hello", "World");

Continue to read, you can write this, the first experience is very good

Functionname1.love = "Hello world! ";

alert (functionname1.love);

Functionname1.test = function () {alert ("Test");}

Functionname1.test ();

2. JQuery $ (document). The difference between ready () and Window.onload

1. Execution time

Window.onload must wait until all elements of the page including the picture have been loaded before they can be executed.

$ (document). Ready () is executed after the DOM structure has been drawn and does not have to wait until the load has finished.

2, write the number of different

Window.onload cannot write multiple at the same time, if there are multiple window.onload methods, only one is executed, followed by one.

$ (document). Ready () can be written multiple at the same time, and can be executed.

3. Simplifying the wording

Window.onload does not have a simplified formulation.

$ (document). Ready (function () {}) can be simply written as $ (function () {}).

Note: The relationship and distinction between window.onload and body.onload, it is best to personally practice.

3, Location.href

1, top.location.href= "url" in the top-level page to open the URL (out of the frame)

2, parent.location.href= "url" opens the URL address in the parent window

3, self.location.href= "URLs" and this.location.href= "URLs" and window.location.href= "URLs" and location.href are all open URL addresses on this page

So I solved a problem: using the IFRAME framework and controlling the user timeout limit, so sometimes the login page appears in a section of the page.

The simple way to handle it is to make a decision on the login page through JavaScript.

<script type= "Text/javascript" >

if (Window!= top)

Top.location.href = Location.href;

</script>

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

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.