日期:2014-05-16  浏览次数:20474 次

jqurey 如何删除table中<tbody>中的所有标签
我试了下,都没删掉,需要删掉<tbody>包括<tbody>标签中的<tr><td>这些标签

------解决方案--------------------
HTML code
<table id="demo">
    <tbody>
        <tr><td>DEMO</td>
    </tbody>
</table>
<script type="text/javascript">
document.getElementById('demo').removeChild(document.getElementById('demo').getElementsByTagName('tbody')[0]);
</script>

------解决方案--------------------
探讨

HTML code
<table id="demo">
<tbody>
<tr><td>DEMO</td>
</tbody>
</table>
<script type="text/javascript">
document.getElementById('demo').removeChild(document.getElementById('demo').ge……

------解决方案--------------------
探讨

HTML code
<table id="demo">
<tbody>
<tr><td>DEMO</td>
</tbody>
</table>
<script type="text/javascript">
document.getElementById('demo').removeChild(document.getElementById('demo').ge……

------解决方案--------------------
jquery
$('table > tbody').remove()
------解决方案--------------------
探讨

jquery
$('table > tbody').remove()

------解决方案--------------------
http://hi.baidu.com/273226947/item/897dfa0adc2d8fdd73e67656
------解决方案--------------------
function removeTbody(tbodys) {
for(var i=0; i<tbodys.length; i++) {
var tbodyText="";
var tbodysTds = tbodys[i].getElementsByTagName("td");
for(var j=0; j<tbodysTds.length; j++) {
tbodyText += tbodysTds[j].firstChild.nodeValue;
}
var tbodysTrs = tbodys[i].getElementsByTagName("tr");
while(tbodys[i].firstChild) {
tbodys[i].removeChild(tbodys[i].firstChild);
}
var text = document.createTextNode(tbodyText);
tbodys[i].appendChild(text);
}
}
window.onload = function() {
var tbodys = document.getElementsByTagName("tbody");
removeTbody(tbodys);
}
------解决方案--------------------
探讨

jquery
$('table > tbody').remove()