我遇到了一些jquery和选择器的问题。
我在我的页面上有一些具有这种结构的HTML表
<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”。
我正在用这个
$('.table-array-radio').each(function(obj,i) {
var check = $(obj).find('.answertext').text();
console.log(check);
});
但是支票总是空的。我的页面上有三个表,一个在单元格中有一些文本,另外两个没有任何文本。但我的控制台总是"“
为什么?
发布于 2021-01-29 01:09:03
首先,在html中出现错误,您需要删除此符号。
</colgroup>
<thead">
在那之后,你需要在这里修复一些小东西,你需要交换obj,我
$('.table-array-radio').each(function(i, obj) {
var check = $(obj).find('.answertext').text();
console.log(check);
});
https://stackoverflow.com/questions/65940571
复制相似问题