dsvd407787736 2017-09-25 06:46
浏览 51

jQuery .each函数在html表上无法正常工作

I have an issue with getting dimensions of a table in jQuery.

I have table which is generated from a loop like this:

if(something) {
    echo '<tr class="trclass" height="'.$a['percentHeight'].'%" colspan="'.$a['col_span'].'">';
}

if(something else) {
    echo '<td class="tdclass" width="'.$a['percentWidth'].'%" rowspan="'.$a['row_span'].'">';
    if (condition == 1) echo $action['1'];
    if (condition == 2) echo $action['2'];
    if (condition == 3) echo $action['3'];
}
echo '</td>';

Where col,row_span and width and height and action are form database.

  1. On every page this table might be different.

  2. Dimensions of a table's skeleton are fine and actions are displaying in appropriate cells, but I want to fit the action dimensions to the cell dimensions.

But when I try to only display in the console the hight of each cell like this:

$('#table tr').each (function() {

    console.log($('td').height());

or this:

$('.tdclass').each (function() {

    console.log($(this).height());

it's displaying only one number and I can't change the css of each cell. Can someone tell me how to do this properly?

  • 写回答

2条回答 默认 最新

  • dqj29136 2017-09-25 06:54
    关注
    $('#table tr').each (function() {
        console.log($($(this).find('td').get(0)).height());
    });
    

    OR

    $('#table tr').each (function() {
      $(this).find('td').each(function(){
        console.log($(this).height());
      })
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题