0

ページ内の URL を自動リンクする必要があります。

例えば

これは HTML コンテンツで、テキスト URL www.example.com とリンクされた URL <a href='www.example.com'> example </a> が含まれています。[http://www.example.com] のように http が続く場合があります。

結果が次のようになる必要があります。

これは HTML コンテンツであり、テキスト URL http://www.example.comとリンク URL http://www.example.comが含まれています。http://www.example.comのように http が続く場合があります。

以下の関数を使用しましたが、www で始まる URL では機能しません。

    jQuery.fn.autolink = function() {
        return this.each(function() {
            // http://、https://、または ftp:// で始まる URL
            var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-\{\}$!|]+(?![\w\s? &.\/;#~%"=-]*>))/g;
            $J(this).html($J(this).html().replace(re, '$1'));
        });
    }

4

2 に答える 2

0

このようなことを試してください。これにより、href 属性とハイパーリンクの html が変更されます。

$("a").each(function(k,v){
   this.attr("href","http://"+this.attr("href"));
   this.html("http://www."+this.html()+".com");
})
于 2013-04-10T07:38:04.027 に答える