无法获取tr元素的属性值 [英] Cannot getting attribute value of the tr element
问题描述
我想将数据从表保存到数据库,所以使用jquery和html属性来获取表值,我区分表上的新旧数据,在tr(表行)上添加属性,即data_histry =new 或者data_histry =old
当我保存时,jquery无法从表属性中获取此属性..
请帮助
我的尝试:
在表格中添加数据
I want to save data from table to database so using jquery, and html attributes to get the table values and i am differentiating new and old data on table from adding a attribute on tr(table row) that is data_histry="new" or data_histry="old"
when i saving then jquery cannot get this attribute from table attribute..
please help
What I have tried:
adding data in table
var markup = "<tr id='tab" + tabid + "' class='test old' style='background-color:#E9E9E9;' data_type='test' data_histry='old'><td class='data-name' medi-id='"+ data[i].tid +"'>" + data[i].name + "</td><td class='data-dis'>" + data[i].descript + "</td><td><button test-id='" + data[i].id + "' type='button' class='btn btn-danger table-delete'></button></td></tr>";
$("#table-body").append(markup);
并希望通过循环从属性获取属性
and want to get property from attribute by the process from loop
console.log($('#tab'+i).attr('data_histry'));
其中#tab是id tr和我正在计算变量
和在控制台上它给我
undefined
where #tab is id of tr and i is counting variable
and on console its giving me
undefined
推荐答案
(#table-body)。append(markup);
("#table-body").append(markup);
并希望通过循环从属性获取属性
and want to get property from attribute by the process from loop
console.log(
('#tab'+ i).attr('data_histry'));
('#tab'+i).attr('data_histry'));
其中#tab是tr的id而我正在计算变量
并且在控制台上它给我
undefined
where #tab is id of tr and i is counting variable
and on console its giving me
undefined
这篇关于无法获取tr元素的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!