修改TD元素Jquery
各位,我需要使用Jquery以编程方式在修改TD元素Jquery,jquery,Jquery,各位,我需要使用Jquery以编程方式在td中动态添加/删除图标。td如下所示 <td> <input type="text" id="target_edit_WEB" class="selectized" style="width:100px; height:25px;" placeholder="Enter ResourceB"> <i class="fa fa-exclamation-triangle" style="color:#D70F0F">&
td
中动态添加/删除图标。td
如下所示
<td>
<input type="text" id="target_edit_WEB" class="selectized" style="width:100px; height:25px;" placeholder="Enter ResourceB"> <i class="fa fa-exclamation-triangle" style="color:#D70F0F"></i>
</td>
请引导我。谢谢这是一种方式:
var $td = $('td:first');
var $icon = $td.find('i.fa:first');
if (!$icon.length) {
$icon = $('<i class="fa fa-exclamation-triangle" style="color:#D70F0F">');
}
// remove icon
$icon.remove();
// add icon
$td.append($icon);
var$td=$('td:first');
var$icon=$td.find('i.fa:first');
如果(!$icon.length){
$icon=$('');
}
//删除图标
$icon.remove();
//添加图标
$td.append($icon);
使用removeClass和addClass的另一种方法
$('.selectized').keyup(function(){
if( $(this).val().length == 0 ){
$(this).next().addClass('fa-exclamation-triangle')
console.log($(this).val())
}
else{
$(this).next().removeClass('fa-exclamation-triangle')
console.log($(this).val())
}
})
查看此
$('td.fa')。hide()
将隐藏$('td.fa')。show()
将显示。还可以使用.remove()和append(),具体取决于要归档的内容。您的问题出在哪里?总TD标记字符串包含在一个变量“cell”中,请告知我建议解决方案的语法您需要更清楚您的标准。什么时候应该显示?它应该什么时候藏起来?其中是total、cell等。total TD标记字符串包含在一个变量“cell”中,请告知我建议解决方案的语法,然后您可以在第一行中使用该字符串,如$TD=$(cell)
,从中创建一个jQuery对象,您可以对其进行操作。感谢Rudi,我做了如下操作,它可以工作var$TD=$(cell);var$icon=$td.find('i.fa:first');$icon.remove();