-3
如果有人知道是可以在div上找到鏈接並使其可點擊的插件?我有div文本:jQuery - 'href'插件?
<div id="mytext">Wow, please go to http://www.google.com - this is my home page ;)</div>
而且我想讓自動點擊鏈接。
如果有人知道是可以在div上找到鏈接並使其可點擊的插件?我有div文本:jQuery - 'href'插件?
<div id="mytext">Wow, please go to http://www.google.com - this is my home page ;)</div>
而且我想讓自動點擊鏈接。
了易於執行的執行:
var url_pattern = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w][email protected])?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w][email protected])[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/;
var content = $("#mytext").text();
var newContent = content.replace(url_pattern, function (link) {
return '<a href="' + link + '" target="_blank">' + link + '</a>';
});
$('#mytext').html(newContent);
其實這是有趣的,我敢肯定你不會找到一個插件在那裏,但你可以做,做一個函數 –
使用'replace'和搜索欄查找正則表達式。 – 2014-03-07 16:19:25
我不知道一個,所以[但是](http://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links)。想要搜索... – giorgio