Javascript jquery-基于css属性添加行
我有大约50行数据。许多行的css属性设置为默认值:无 我只想添加显示为none的行的数据。jquery中是否有关于此的内容 我的 现在,我正在像这样计算,结果都错了Javascript jquery-基于css属性添加行,javascript,jquery,Javascript,Jquery,我有大约50行数据。许多行的css属性设置为默认值:无 我只想添加显示为none的行的数据。jquery中是否有关于此的内容 我的 现在,我正在像这样计算,结果都错了 $(document).ready(function () { $(".sum").click(function() { var total = 0; $(this).closest('tr').hide(); $('table tr td:nth-of-type(1)').each(function()
$(document).ready(function () {
$(".sum").click(function() {
var total = 0;
$(this).closest('tr').hide();
$('table tr td:nth-of-type(1)').each(function() {
total += parseFloat($('table tr td:nth-of-type(1)').text()) || 0;
$('.sum').text(" "+total);
});
});
});
试一试
演示:试试看
演示:试试看
演示:试试看
演示:
$(document).ready(function () {
$(".sum").click(function () {
var total = 0;
//all first td elements of the table where tr id visible
$('table td:nth-of-type(1):visible').each(function(){
total += parseFloat($(this).text()) || 0;
})
//display the total
$(this).text(" " + total);
});
});