[英]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.