The common and important methods of jquery (Target,arguments,slice,substring,data,trigger)-(a)

Source: Internet
Author: User

1.jquery data (name)

The data () method attaches to the selected element or gets data from the selected element.

$ ("#btn1"). Click (function() {  $ ("div"). Data ("greeting", "Hello World");}); $ ("#btn2"). Click (function() {  alert ("div"). Data ("greeting");});

2.jquery arguments

Arguments is a reference to an argument object that is a class array object.

Index of arguments from 0,,.... increment, corresponding to the argument one by one.

The Arguments.length property represents the number of arguments

Arguments must not be an array, it is a long comparison of an object like an array, although there is also the length property

Arguments each function will have, therefore, Arguemnts will only find its own arguments inside, unable to refer to the outer arguments

//round area, rectangular area, triangular area    functionArea () {if(Arguments.length = = 1) {alert (3.14 * Arguments[0] * arguments[0]); } Else if(Arguments.length = = 2) {alert (arguments[0] * arguments[1]); } Else if(Arguments.length = = 3) {alert (arguments[0] + arguments[1] + arguments[2]); } Else{return NULL; }}//calledArea (10,20,30); 

3.jquery Target () event. Target

The target property specifies which DOM element triggers the event.

$ ("p, button, H1, H2"). Click (function(event) {  $ ("div"). html ("triggered by a" + Event.target.nodeName + "element." );}); <p></p><button></button>//  When you click on the P tab: the Click event is triggered by the P element ....

4.jquery Trigger (event,[reference 1, Parameter 2, ... ) ])

trigger The () method triggers the specified event type for the selected element. (customizable events, can pass parameters) custom events are important and useful!

  myevent for custom event names   $ ( "#p1"). Bind ("MyEvent", function   (STR1,STR2) {alert (str1  + ' + s           TR2);           }); $ ( "#p1"). Trigger ("MyEvent", ["Hello", "World"  //  can also be written like this:   $ ( "#p1"). Bind ("MyEvent", function  Span style= "color: #000000;"           > (STR1,STR2) {alert (str1  + "+ str2); }). Trigger ( "MyEvent", ["Hello", "World"]); 

5.js substring (start,stop)

The substring () method is used to extract the character of a string intermediary between two specified subscripts.

the substring returned by the substring () method includes Start characters, but does not include Stop character at the same place.

var str= "helloworld!" document.write (str.substring (3,7)) // Results Lowo var str= "Hello  world!" // There are two null characters document.write (str.substring (3,7))// result lo//  The result of the two is different, the empty string between the strings occupies the index! 

See clearly no r this stop character!

important: and Span style= "color: #000000;" >  slice ()   and   substr () The   method differs in that substring () does not accept negative parameters.

6.js Slice (start,stop)

The Slice () method extracts a portion of a string and returns the extracted part with a new string. with the above substring does not include the character at the stop;

There is another difference:start,stop can use negative numbers! that is,-1 refers to the last character of the string, 2 refers to the second-lowest character, and so on.

The data () method attaches to the selected element or gets data from the selected element.

The common and important methods of jquery (Target,arguments,slice,substring,data,trigger)-(a)

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.