Blogger Information
Blog 100
fans 8
comment 2
visits 149889
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jquery获取表格中循环出的行内单元格数据
lilove的博客
Original
3219 people have browsed it
//注意由于要多次选择相同属性单元格元素只能用class选择器(id唯一性优先级不适用)
$(".table_tr").each(function(){
        $("#edit_btn",this).click(function(){
            var cate_name = $(this).parents("tr").find("td:nth(1)").text();
            var cate_order = $(this).parents("tr").find("td:nth(2)").text();
            var cate_type = $(this).parents("tr").find("td:nth(3)").text();
            $('#edit_cate_name').val(cate_name);
            $('#edit_cate_order').val(cate_order);
            $('#edit_cate_type').val(cate_type=='单页面'?0:1);
        });
    });

触发元素设置id="edit_btn",表格行数据设置class="table_tr",注意一定要加this。

代码中:

$(this).parents("tr").find("td:nth(1)").text();

获取到的数据是string类型。如果单元格很多,可循环获取。

赋值到其他元素中:

$('#edit_cate_name').val(cate_name);
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post