下面我有一个简单的表,我试图循环并获取每行中每个单元格的值(如果有的话)<td>s
。
但是我得到一个错误find
,说不存在,并且添加了 jquery。你能帮忙吗?谢谢
$(document).ready(function () {
var x = $('table tr:has(td)');
$.each(x, function (i, v) {
alert(
v.find('td').eq(0).text()); + " ----" + v.find('td').eq(1).find('option:selected').val(););
});
});
<table>
<tbody>
<tr>
<th>a</th>
<th>b</th>
</tr>
<tr>
<td>test</td>
<td>
<select>
<option value="yes">yes</option>
<option selected="selected" value="no">no</option>
</select>
</td>
</tr>
<tr>
<td>test</td>
<td>
<select>
<option value="yes">yes</option>
<option selected="selected" value="no">no</option>
</select>
</td>
</tr>
<tr>
<td>test</td>
<td>
<select>
<option value="yes">yes</option>
<option selected="selected" value="no">no</option>
</select>
</td>
</tr>
<tr>
<td>test</td>
<td>
<select>
<option value="yes">yes</option>
<option selected="selected" value="no">no</option>
</select>
</td>
</tr>
<tr>
<td>test</td>
<td>
<select>
<option value="yes">yes</option>
<option selected="selected" value="no">no</option>
</select>
</td>
</tr>
</tbody>
</table>