【发布时间】:2016-01-02 00:05:13
【问题描述】:
我已成功使链接可点击,但如何让它们再次恢复到不可点击状态?
HTML
<div id="links">
http://google.com <br>
http://facebook.com <br>
http://youtube.com
</div>
<button>Toggle!</button>
JavaScript
$.fn.replaceUrl = function() {
var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
this.each(function() {
$(this).html(
$(this).html().replace(regexp,'<a href="$1">$1</a>')
);
});
return $(this);
}
$('button').click(function(){
$('div').replaceUrl();
});
【问题讨论】:
-
小提琴是添加到问题中的好东西,但也请将代码发布到问题中。这样人们可以在 jsFiddle 离线时帮助您,并且这个问题将来也会有用。
标签: javascript jquery toggle