[英]How do I use JQuery or JavaScript to remove all links in a table?
我有一个表,我想导出到Excel但我不希望任何超链接通过。 那可能吗?
我注意到在JQuery删除图像的线程中正在做类似的事情,但我不是和我需要的一样吗?
如果可能的话,我还想将文字保留在标签内?
例:
<table class="surveyTable" id="Summary">
<tr>
<th>Section</th>
<th title="3584">
<a href="test.php?id=3584">
Call 1
</a>
</th> ...
我想有能力导出上面没有href但仍保留“呼叫1”,但也许这是不可能的?
谢谢!
是的,这应该相当简单,使用replaceWith
的函数回调签名:
$('#summary a').replaceWith(function() {
return this.childNodes;
});
去除各a
元素,并替换每一个与它的所有子节点。 这意味着您保留任何格式。
如果你想要纯文本,那也很容易实现:
$('#summary a').replaceWith(function() {
return $.text([this]);
});
尝试这个:
$('th a').each(function(){
$(this).replaceWith($(this).text())
})
我还没有测试语法正确性,但是,这些方面应该有用:
$('#Summary a').each( function() {
$(this).parent().html($(this).html());
}
$("#Summary").find('a').each(function(){
$(this).attr('href','#');
});
我相信这会解决你的目的。
$('.surveyTable tr th a, .surveyTable tr td a').each(function(){
$(this).replaceWith($(this).text());
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.