【发布时间】:2017-03-09 21:39:20
【问题描述】:
我正在使用一个函数将所有以文本形式写出的超链接转换为实际工作的超链接。但是,该函数还针对每个 <p> 内部的 <img src="http://linktoimage.jpg"> 将它们分解为:
<img src="<a href="http://linktoimage.jpg">http://linktoimage.jpg</a>/>
这是函数,我尝试添加.not('img'),但这没有帮助,那么如何忽略所有子img-tags?
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> ') );
});
【问题讨论】:
标签: javascript jquery html image hyperlink