【问题标题】:jquery - Rowspan table in PHPjquery - PHP 中的 Rowspan 表
【发布时间】:2019-10-22 14:13:46
【问题描述】:

它在 td 中用作 .text

   <td>'.$row["j_pic"].'</td>

it works.jpg

但它不适用于 td 中的 img

<td>'."<img src='picture/".($row["j_pic"])."' style='width:20%' />".'</td>

it not works.jpg

jQuery

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
$(document).ready(function() { 
var span = 1; 
var prevTD = ""; 
var prevTDVal = ""; 
$("#myTable tr td:first-child").each(function() { //for each first td in every tr 
var $this = $(this); 
if ($this.text() == prevTDVal) { // check value of previous td text
span++; 
if (prevTD != "") { 
prevTD.attr("rowspan", span); // add attribute to previous td $this.remove(); // remove current td 
} } else { 
prevTD = $this; // store current td 
prevTDVal = $this.text();
span = 1; } }); });

【问题讨论】:

  • 分享你渲染的html
  • 为什么你的示例代码这么不清楚。我在看一个 PHP 文件,还是什么?您需要包含更多上下文代码。无法知道这是如何解析的。

标签: javascript php jquery while-loop tablerow


【解决方案1】:

我认为您想比较 HTML 内容,然后使用 html() 方法而不是 text() 方法,因为 text() 方法只返回元素内的文本内容。

if ($this.html() == prevTDVal)

【讨论】:

  • @PitchayatisaHirunwong:很高兴它有帮助:)
猜你喜欢
  • 2019-08-08
  • 1970-01-01
  • 2019-02-20
  • 2011-03-10
  • 2015-11-12
  • 1970-01-01
  • 2014-04-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多