【Foreword】
Student problem: jquery failed to get the current row data of the table. Some students output undefined, and some save the wrong data type. This problem has been introduced before. It's a commonplace, and I'll re-emphasize it here.
【main body】
(1) Click event: It can be bound in jquery, or the details can be written in the label.
(2) The function method can also be written in a variety of ways, here I list two
①Start from the current click
$(document).ready(function(){ $('.showBtn').on('click',function(){ var title = $(this).parents('tr').children("td").get(1).innerHTML; console.log(title) }) })② Traverse the table first, and start when the corresponding button is clicked
$(".myclass").each(function(){ $(".sub",this).click(function(){ alert($(this).parents("tr").html()); }); });
【Summarize】
jQuery gets the current row data. Many students forget that the jQuery object is converted into DOM when using it, so it is stuck here. . . . . . . . . . . . . . . It is recommended to have time to study the conversion of js and jquey objects
$(function() { $(".myclass").each(function(){ var tmp=$(this).children().eq(3); var btn = tmp.children (); btn.bind("click",function(){ var id=btn.parent().parent().children("td").get(0).innerHTML; var name=btn.parent().parent().children("td").get(1).innerHTML; var age=btn.parent().parent().children("td").get(2).innerHTML; alert("id="+id+" name="+name+" age="+age); }); }); });