0

我想删除我的 img 标签中的某些字符,这些字符是循环中的列表项。我想摆脱: " li="" ..."但保持我的图像 src 完整。任何帮助都是极好的!!

 This is my output:

   <li>
   <img li="" ...<="" src="myimage.jpg?932">
   <li>

这是我尝试过但没有运气...

$("#blogs li").each(function(i) {
   $(this).children('img').find('...<="" li="">').remove().end().html();
});
4

4 回答 4

3

签出:removeAttr

如:

$("#blogs li").each(function(i) {
   $(this).children('img').removeAttr('li');
});
于 2012-09-14T20:51:46.363 回答
2

您应该修复循环代码,而不是使用 JavaScript。尝试使用。 replaceWith方法。

$("#blogs li img").replaceWith(function(){
   return '<img src="'+this.src+'"/>';
})
于 2012-09-14T20:52:43.427 回答
2

不需要 .each:

$("#blogs li img").removeAttr('li');
于 2012-09-14T20:55:50.613 回答
0

看起来 li 没有结束标签我担心解析器会失败:/

你试过这个

$("#blogs li").each(function(i) {
   alert($(this).html()); // or alert($(this).children().html());
});

为什么不尝试在服务器端进行修复?

于 2012-09-14T21:03:00.580 回答