使用JavaScript自动为网址文本添加超链接
有些情况可能需要用到这个,例如网页里有大量链接,以文本形式存在。手动添加超链接显然不现实,这时可以用JavaScript配合正则匹配和replace()替换函数解决。将下面代码加至</body>前,绑定内容父标签ID名称即可使用,原生JS用法,不用加载jQuery库。
HTML
<div id="demo">包含网址的文本内容</div>
JavaScript
window.onload = function() { var label = document.getElementById("demo"); var text = label.innerHTML; var regular = /((https|http):\/\/[\w.\/\:\-]+)(?![^<]+>)/gi; label.innerHTML = text.replace(regular, "<a href='$1' target='_blank'>$1</a>"); }
Hi, very nice website, cheers!
——————————————————
Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
——————————————————
Check here: https://www.reliable-webhosting.com/
priligy dapoxetine for sale https://salemeds24.wixsite.com/dapoxetine
where can i order cialis online http://www.lm360.us/
super vidalista 20mg https://vidalista.mlsmalta.com/
ivermectin usa https://ivermectin.webbfenix.com/
sildenafil citrate 20 mg cost http://droga5.net/
vidalista when to take https://vidalista.buszcentrum.com/
has hydroxychloroquine been successful https://hydroxychloroquine.mlsmalta.com/
how much ivermectin is too much https://ivermectin.mlsmalta.com/
generic viagra and vidalista https://vidalista40mg.mlsmalta.com/
warnings for cialis https://wisig.org/
is tamoxifen used after menopause https://tamoxifen.mrdgeography.com/
need refill no doctor https://buymeds.mlsmalta.com/
proair hfa inhaler https://amstyles.com/
hydroxychloroquine treating covid 19 https://hydroxychloroquinee.com/
how much is cialis 10mg https://cleckleyfloors.com/
how to stop taking plaquenil https://hydroxychloroquine.wisig.org/
cenforce patent expiration date extended http://cavalrymenforromney.com/
cialis 20mg pills dosage https://cialis.cleckleyfloors.com/
cialis 20mg pills dosage https://cialis.grassfed.us/
I simply could not leave your web site prior to suggesting that I
actually enjoyed the usual info a person provide
on your visitors? Is going to be again regularly in order to check out new posts http://antiibioticsland.com/Augmentin.htm
generic cialis mastercard http://cialis.anafassia.com/
cialis canadian pharmacy online https://cialis.grassfed.us/
cialis canadian pharmacy online https://cialis.adicbc.com/
Hi, just wanted to mention, I loved this blog post.
It was helpful. Keep on posting! http://herreramedical.org/aurogra
http://vsdoxycyclinev.com/ – doxycycline 100mg india
ivermectin mange treatment https://ivermectin1st.com/
online viagra no prescription viagra without a doctor prescription
tadalafil 40 mg daily https://elitadalafill.com/ tadalafil daily use
buy viagra online usa buy viagra online canada
cost of viagra
tadalafil online canadian pharmacy – eli lilly tadalafil tadalafil vs sildenafil
tadalafilo http://essinreceta.com/ farmacia coliseum barcelona
buy ed drugs ed pills without a doctor prescription
legal to buy prescription drugs from canada
Vhsjwc – should annotated bibliographies be double spaced Qzwozx osjzhg
cheap ed pills from canada buy ed pills from canada
cheap ed pills
buy hydroxychloroquine online https://hydroxychloroquinex.com/
Jan. 21, 2016 source: what is cialis black
Vtegvo – natural ed pills Csioew tpyjmf
video of transurethral alprostadil admimistering https://alprostadildrugs.com/ muse alprostadil suppository