首页 >社区问答列表 >javascript - php循环第二次时添加自定义data 属性

javascript - php循环第二次时添加自定义data 属性

<?php foreach($header as $rowItem): ?>
<tr>
    <?php foreach($rowItem as $headerItem): ?>
        <th data-tablesaw-priority="persist" id="<?= $headerItem['id'] ?>" class="<?= $headerItem['class'] ?>"
        <?= (isset($headerItem['colspan']))?'colspan="'. $headerItem['colspan'] .'"':'' ?>
        <?= (isset($headerItem['rowspan']))?'rowspan="'. $headerItem['rowspan'] .'"':'' ?>
        <?= (isset($headerItem['style']))?'style="'. $headerItem['style'] .'"':'' ?> >
            <?= $headerItem['text'] ?>
        </th>
    <?php endforeach ?>
</tr>

<?php endforeach ?>

此循环会有三个<tr> 标签,现在需要在第二个<tr>标签里的<th>添加自定义属性。这需要如何编写?

  • 学习ing
  • 学习ing    2017-06-29 10:10:291楼

    方法一,使用foreach,新增一个count变量,记录循环次数,如果$count == 1,接下来做该做的事

    方法二,使用for,在$i==1时做该做的事

    for($i=0;$i<count($header);$i++)
    {
        if($i === 1) {
            //
        }else{
            //
        }
    }

    +0添加回复

  • 回复