<分区>
我有一个非常简单的表格,其中包含最少的 html 标签,例如:
<table id="test">
<tr><td>some table cell</td></tr>
</table>
我正在尝试检查标签是否存在。奇怪的是:jquery 说“是的,有一个 tbody 标签”,即使我没有定义一个!这里发生了什么?
$('table#test').each(function(){
var tbody = $(this).find('tbody');
//how can there be a tbody when there is no <tbody> tag defined?
console.log(tbody.length); //gives 1, should be 0 though as there is no tbody
});
使用 jQuery 1.6.4 在 Chrome 28.0、Firefox 22.0 中测试(因为当前项目需要它,尽管它也发生在 jQuery 2.0.2 中)
这里还有一个jsFiddle:http://jsfiddle.net/nerdess/rH5Lf/