プレーンテキストのURLをに変換する必要があります<a href=""></a>
。動作するJSコードを見つけました。私の問題は、HTML構造でコードを変更し、現在のコードをforeach内に配置する必要があることです。
私のhtml:
<div class="content">Some text with links</div>
<div class="content">Some text with links</div>
<div class="content">Some text with links</div>
<div class="content">Some text with links</div>
<div class="content">Some text with links</div>
<div class="content">Some text with links</div>
JS:
$(function()
{
var re = /(https?:\/\/(([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?))/ig;
$('.content').html($('.content').html().replace(re, '<a href="$1" title="">$1</a>'));
});
上記のJSは機能しますが、すべてのdivに同じコンテンツを入力します。このコードをforeachに入れようとしましたが、失敗しました。私の貧弱なJSの知識は、私にSOでこれを尋ねさせます。
このコードをforeachループに入れる方法についていくつかの手がかりを与えることができますか?