jquery's attr () attribute __jquery

Source: Internet
Author: User
Problem Description

In the development of the Cuckoo cloud, an AJAX approach is needed to display the details of the task, to reply to the task on this page, to delete the comment, to comment on the comment (that is, to comment on the building), but the building's function has never been solved. JavaScript Code Resolution

var cid = data.data.task.comment[i].cid;
replycomment.id = CID
replycomment.addeventlistener ("click", Function () {
document.getelementsbyname ("task _id ") [0].value = ID;
document.getElementById ("Parentcomment"). Value = Replycomment.id;
alert (replycomment.id);
$ ("#comment_area"). focus ();//Spotlight to textarea for input comment content
},false);
CID is using AJAX methods to upload from the background to the front end of this comment ID value to the replycomment, that is, each response button binding to the corresponding comments to each reply button binding listening time, when clicked reply to trigger the anonymous function, where AddEventListener () The third parameter of the function represents the event mechanism for bubbling or capturing, referencing the event mechanism of JS using the above function, the result of the operation is an error. Since the code above is running in for, the value of each alert is the last comment of the loop this ID, and it does not play a binding role, which is where the pit is.
var cid = data.data.task.comment[i].cid;
replycomment.id = CID
replycomment.addeventlistener ("click", Function () {
var strtemp = $ (this). attr ("id");
Document.getelementsbyname ("task_id") [0].value = ID;
document.getElementById ("Parentcomment"). Value = $ (this). attr ("id");
$ ("#comment_area"). focus ();//Spotlight to textarea for input comment content
},false);
Modified as the appeal code, using $ (this). attr ("id") to achieve a comment on the binding of the Reply button, and its ID as the parent node ID to the background, the new comment for its child comments, the implementation of the building function.
Detailed this keyword in JS and jquery
jquery's attr () attribute

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.