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