首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用jquery查找表中没有文本的单元格

使用jquery查找表中没有文本的单元格
EN

Stack Overflow用户
提问于 2021-01-28 23:51:08
回答 1查看 20关注 0票数 0

我遇到了一些jquery和选择器的问题。

我在我的页面上有一些具有这种结构的HTML表

代码语言:javascript
运行
复制
<table class="table-array-radio">
  <colgroup class="col-responses">
    <col class="col-answers" style="width: 33%;">
    <col class="ls-col-odd" style="width: 6.1%">
    <col class="ls-col-even" style="width: 6.1%">
    <col class="ls-col-odd" style="width: 6.1%">
    <col class="ls-col-even" style="width: 6.1%">
  </colgroup>
  <thead">
    <tr>
      <td class=""></td>
      <th class="answer-text">0</th>
      <th class="answer-text">1</th>
      <th class="answer-text">2</th>
      <th class="answer-text">3</th>
      <th class="answer-text">4</th>
    </tr>
    </thead>
    <tbody>
      <tr class="answers-list">
        <th class="answertext control-label">sotto-domanda 1</th>
        <td class="answer_cell_1 answer-item radio-item"></td>
        <td class="answer_cell_2 answer-item radio-item"></td>
        <td class="answer_cell_3 answer-item radio-item"></td>
        <td class="answer_cell_4 answer-item radio-item"></td>
        <td class="answer_cell_11 answer-item radio-item"></td>
      </tr>
    </tbody>
</table>

我简化了表格,但结构是这样的。如果我的主体中有一个包含任何文本的".answertext“类的单元格,我必须检查JQuery,如果这个单元格是空的,我必须将".col-answers”类的宽度设置为“0”。

我正在用这个

代码语言:javascript
运行
复制
$('.table-array-radio').each(function(obj,i) {
    var check = $(obj).find('.answertext').text();
    console.log(check); 
});

但是支票总是空的。我的页面上有三个表,一个在单元格中有一些文本,另外两个没有任何文本。但我的控制台总是"“

为什么?

EN

回答 1

Stack Overflow用户

发布于 2021-01-29 01:09:03

首先,在html中出现错误,您需要删除此符号。

代码语言:javascript
运行
复制
</colgroup>
  <thead">

在那之后,你需要在这里修复一些小东西,你需要交换obj,我

代码语言:javascript
运行
复制
$('.table-array-radio').each(function(i, obj) {
    var check = $(obj).find('.answertext').text();
    console.log(check); 
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65940571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档