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>添加自定义属性。这需要如何编写?
解决方案
方法一,使用foreach,新增一个count变量,记录循环次数,如果$count == 1,接下来做该做的事
方法二,使用for,在$i==1时做该做的事
for($i=0;$i<count($header);$i++)
{
if($i === 1) {
//
}else{
//
}
}
这篇关于javascript - php循环第二次时添加自定义data 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文