Javascript 尝试基于innerHTML删除父节点-无法读取属性';nodeValue';未定义的
我需要删除删除附件的选项。我尝试使用的函数出现以下错误:无法读取未定义的属性“nodeValue” 我厌倦了这样做:Javascript 尝试基于innerHTML删除父节点-无法读取属性';nodeValue';未定义的,javascript,jquery,sharepoint,hide,Javascript,Jquery,Sharepoint,Hide,我需要删除删除附件的选项。我尝试使用的函数出现以下错误:无法读取未定义的属性“nodeValue” 我厌倦了这样做: function hideDelete (){ $("a").filter(function () { return $.trim(this.childNodes[0].nodeValue) === "Delete"; }).closest("td").hide(); } HTML: <td class="ms-propert
function hideDelete (){
$("a").filter(function () { return $.trim(this.childNodes[0].nodeValue) === "Delete"; }).closest("td").hide();
}
HTML:
<td class="ms-propertysheet"><img alt="Delete" src="/_layouts/images/rect.gif"> <a tabindex="1" href="javascript:RemoveAttachmentFromServer('{2088EB08-E376-4637-A6F9-35675AF46E35}',1)">Delete</a></td>
jQuery:
$('td a').each(function(){
var $this = $(this);
if($this.text() == 'Delete'){
$this.parent().html('');
}
});
在您的代码片段中,td始终是直接的父级。与其试图隐藏内联元素,您可以隐藏元素的内容,或者在本例中清空内容。哦,这里您不是隐藏单元格,而是替换其中的内容?它正在替换该单元格的全部内容。您可能希望使用.html(“”)来避免单元格崩溃。@Daniel为什么不直接调用
.parent()
上的.hide()
,而不是.html(“”)
?隐藏单元格将导致其他单元格改变格式。请尝试:返回此.childNodes[0]&&&$.trim(此.childNodes[0].nodeValue)=“删除”代码>