Javascript Don';t从表中删除内容td第一个子项
() 我想排除删除td first child中的文本,以便保留文本Javascript Don';t从表中删除内容td第一个子项,javascript,jquery,html,css-selectors,Javascript,Jquery,Html,Css Selectors,() 我想排除删除td first child中的文本,以便保留文本Sale,Age,例如: 原始HTML: <table class="toptable"><thead> <tr> <th class="dsdds_image">-</th> <th class="r3dde_image">-</th> <th class="s43434_image">-</th&
Sale
,Age
,例如:
原始HTML:
<table class="toptable"><thead>
<tr>
<th class="dsdds_image">-</th>
<th class="r3dde_image">-</th>
<th class="s43434_image">-</th>
</tr></thead><tbody>
<tr>
<td class="44665_description">Name</td>
<td class="3434d_description">Alan</td>
<td class="a34df_description">John</td>
</tr>
<tr>
<td class="dfs4rf_title">Age</td>
<td class="adf43df_title">8</td>
<td class="dsffds4_title">9</td>
</tr></tbody>
</table>
我使用if语句检查它是否在remove函数之前是:first child
,但它仍在清除第一个子文本。谁能给我一些建议吗
$('#cleartable').on('click', function () {
var clear = $(".toptable td,.toptable th")
if (clear.not(':first-child')){ //*******This part
clear.contents().filter(function(){
return this
}).remove();
}
clear.each(function() {
var $this = $(this)
if ($this.attr('class')){
var changeclass = $(this).attr("class");
$this.attr('class',changeclass.replace(/^[^_]+/,"placeholder"));//See this?
}
});
});
试一试
试试看
试试看
试试看
也许是一个简单的方法:
var clear = $(".toptable td+td,.toptable th")
也许是一个简单的方法:
var clear = $(".toptable td+td,.toptable th")
也许是一个简单的方法:
var clear = $(".toptable td+td,.toptable th")
也许是一个简单的方法:
var clear = $(".toptable td+td,.toptable th")
在您正在使用的代码中
if (clear.not(':first-child'))
jQuery的.not()将返回一个jQuery实例而不是布尔值,因此这可能不是您所期望的
一个简单快捷的方法就是
clear.not(':first-child').text('');
在您正在使用的代码中
if (clear.not(':first-child'))
jQuery的.not()将返回一个jQuery实例而不是布尔值,因此这可能不是您所期望的
一个简单快捷的方法就是
clear.not(':first-child').text('');
在您正在使用的代码中
if (clear.not(':first-child'))
jQuery的.not()将返回一个jQuery实例而不是布尔值,因此这可能不是您所期望的
一个简单快捷的方法就是
clear.not(':first-child').text('');
在您正在使用的代码中
if (clear.not(':first-child'))
jQuery的.not()将返回一个jQuery实例而不是布尔值,因此这可能不是您所期望的
一个简单快捷的方法就是
clear.not(':first-child').text('');