$.data (data, "")

Source: Internet
Author: User

Today in two development time, see the source code of news list is Aajax get, click News content trigger Edit, I did not see the news ID but can find information.

While watching the $.ajax traversal assignment, $TR ("<a> News content </a>"). Data ("Data", "obj") binds the JSON data of this news, as long as $.data ("Data") is available for this array when editing

1. Basic syntax for $data

Data ([Key],[value])

Stores or reads data on an element, returning a jquery object.

When the parameter has only one key, the value corresponding to the key stored in the DOM is read by the jquery object, and it is worth noting that if the browser supports HTML5, it can also read the values stored in the DOM using data-[key] = [value]. See the last example.

When the parameter is two, the data for the Key-value key-value pair is stored in the DOM corresponding to the jquery object.

If the jquery collection points to multiple elements, the corresponding data is set on all elements. Instead of creating a new expando, this function can store data in any format on an element, not just a string.

V1.4.3 new usage, data (obj) can be passed in the form of Key-value.

Instance of 2.$.data

2.1

Storing data on a div:<div><div>

jquery code;

$("Div"). Data ("blah");//undefined$("Div"). Data ("blah","Hello");//blah set to Hello$("Div"). Data ("blah");//Hello$("Div"). Data ("blah", the);//set to$("Div"). Data ("blah");// the$("Div"). Removedata ("blah");//Remove blah$("Div"). Data ("blah");//undefined

2.2

Save the name/value pair data on a div:<div><div>

jquery code;

$("Div"). Data ("Test", {first: -, Last:"pizza!" });$("Div"). Data ("Test"). First//;$("Div"). Data ("Test"). Last//pizza!;

3. I have seen

Assignment value:

$.each (data, function (n, obj) {console.log (obj); if(Currentstatus = ="Mreg") {                                //Fillreg (obj);$("#task-table"). Append ("<tr class= ' Mreg ' ><th></th><th>"+ Obj.t.time +"</th><th colspan= ' 3 ' >"+ Obj.t.rate +"%</th><th colspan= ' 2 ' >"+ Obj.t.worktime +"</th></tr>"); $.each (obj.lt, function (n, data) {//console.log (data);                                    varTR = $ ("<tr><th>"+ (n +1) +"</th><th ><a href= ' # ' onclick= ' Edittask (this) ' >"+ Data.content +"</a></th><th>"+ Data.rate +"</th><th>"+ Data.project +"</th><th>"+ Data.category +"</th><th>"+ Data.worktime +"</th><th>"+ Data.endtimesta +"</th></tr>"); Tr.find ("a"). Data ("Data", data); ------------Focus $ ("#task-table"). Append (tr); })                            }                            Else{Fillcou (obj); }                        });

Edit:

        varEdittask =function (sender) {varobj = $ (sender). Data ("Data"); //Get task InformationCurrentID =obj.id; $('#content'). Val (obj.content); $('#project'). Val (Obj.project); $('#category'). Val (obj.category); $("#worktime"). Val (obj.worktime); $("#endtime"). Val (obj.endtime); $("#rateO"). Val (obj.rate); $("#rateO"). Text (obj.rate+"%"); }

$.data (data, "")

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.