$. Data Applications under $. extend and $. fn,. extend. fn

Source: Internet
Author: User

$. Data Applications under $. extend and $. fn,. extend. fn

1. First, we will study $. data

1) code snippet

<Body onload = "window. scrollTo (0, 1);">

<H1 class = "th"> Welcome <Input id = "test" type = "text" data-age = "5725" name = "nam" value = "123"/>

</Body>

<Script type = "text/javascript">

$ (Function (){

Var val = $ ("# test"). data ('age ');

$ ("# Test"). data ('name', 19); // assign a value in jquery
Var val1 = $ ("# test"). data ('name ');

Console. log (val + '---' + val1 );

});

</Script>

Note: add the data-name attribute to the tag to call the value of the variable named after data-in $. data.

2) connection code, $. data Usage in $. fn

$. Extend ($. fn ,{


ShowAge: function (){
Console. log (this [0]. dataset. age );
}
});

$ ("# Test"). showAge ();

Note: Here this [0] indicates the object for reading tag attributes.

 

9. code snippet

<Body onload = "window. scrollTo (0, 1);">

<H1 class = "th"> Welcome


<Input type = "text" id = "uname" name = "nam" value = "123"/>
<Input type = "text" name = "name" value = "123456"/>

<Input type = "button" name = "btn" value = "vla"/>

</Body>

<Script type = "text/javascript">
$ (Function (){
Var a = {
Name: "AB ",
Func: "onely"
};
$. Extend ($. fn ,{
ShowName: function (){
Console. log ("sdfsd ");
},
EchoName: function (op ){
// $. Data (this [0], 'name', 'dataname ');
Var val = $. data (this [0], 'name ');

Console. log (val );
}

});

Var option = {
Name: "dddd"
};
$ ("# Uname"). data ('name', 'ddddd ');
$ (": Input"). echoName (option );



});
</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.