2

我有一个 HTML 字符串。我想改变这个:

<table >
  <tr>
      <td><a href="/link.html" onclick="javascript:aFunction()">some text</a></td>
      <td><a href="/anotherlink.html">some more text</a></td>           
  </tr>
</table>

进入这个:

<table >
  <tr>
      <td>some text</td>
      <td>some more text</td>           
  </tr>
</table>
4

2 回答 2

2

在 jQuery 1.4+ 中,您可以将函数传递给.replaceWith(),如下所示:

​$("table a")​.replaceWith(function() { return this.innerHTML; });​

你可以在这里试一试

如果你真的有一个字符串,而不是元素,它看起来像这样:

var html = '<table>...{rest of string}...</table>';
var o=$(html).find('a').replaceWith(function(){ return this.innerHTML; }).end();​

你可以在这里试试那个版本

于 2010-09-16T21:24:29.930 回答
0
$(function(){
$('td a').each(function(){
   $(this).replaceWith($(this).text());
});
});
于 2010-09-16T21:22:54.737 回答