0
我正在使用函数将所有写在文本中的超链接转换为实际工作的超链接。然而,功能还针对每个<img src="http://linktoimage.jpg">
里面<p>
打破他们像:使用jQuery转换超链接标记时忽略图像标记
<img src="<a href="http://linktoimage.jpg">http://linktoimage.jpg</a>/>
这是函数,我试图添加一个.not('img')
但这并没有帮助,所以我怎么忽略所有儿童的img标签?
JS-功能:
jQuery('p').each(function(){
jQuery(this).not('img').html(jQuery(this).html().replace(/((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g, '<a href="$1">$1</a> '));
});
这是很整洁伴侣!干杯。 –
很高兴能有所帮助 –