jQuery统一给a标签的href属性添加前缀

2021年10月4日 09:55 by wst

web开发

解决页面上显示pdf文件的问题

由于网站中有大段的文字需要显示,于是想到用PDF的形式直接展示(写页面还是太麻烦),最终在网上找到一个好用插件pdf.js,在整个使用过程中也是走了一些弯路,在此做个记录。

原来的显示方式

直接把超链接设置为pdf的文件路径

<ul class="course">
    <li>
        <a href="./docs/刘总被采访记录.pdf" target="_blank" class="btn btn-primary" role="button">
            刘总被采访记录</a>
    </li>  
    <li>
        <a href="./docs/刘总心路历程-做更好的脱模剂.docx" target="_blank" class="btn btn-primary" role="button">
            刘总心路历程-做更好的脱模剂</a>
    </li>
    <li>
        <a href="./docs/轻质混凝土脱模剂的试验方法.docx" target="_blank" class="btn btn-primary" role="button">
            轻质混凝土脱模剂的试验方法</a>
    </li> 
    <li>
        <a href="./docs/产品使用说明书.pdf" target="_blank" class="btn btn-primary" role="button">
            产品使用说明书</a>
    </li>                    
</ul>

这样做的效果是,浏览直下载了这个文件,体验不好。

新的显示方式

<a href="pdfjs-2.10.377-dist/web/viewer.html?file=http://127.0.0.1:5500/docs/%E5%88%98%E6%80%BB%E8%A2%AB%E9%87%87%E8%AE%BF%E8%AE%B0%E5%BD%95.pdf">点击查看pdf内容</a>

问题:修改起来比较麻烦,之前已经写好了,十几个href一个个改太费劲。

思考

既然是相同的前缀,那么这不是程序最擅长干的事吗?于是想到了jQuery,页面加载后,统一进行修改。作为一个后端程序员,jQuery着实不熟,中间走了一些弯路,好在最终解决了,方案如下:

<script>
$(function () {

    var url_pre = "pdfjs-2.10.377-dist/web/viewer.html?file="
    $("#course a").map(function(){
        console.log("this", this)
        this.href = url_pre + this.href
        return this
    })

})
</script>

重点

1. 先找到要改的元素,然后利用map方法修改,同时注意this的用法。

2. PDF.js的用法:官网连接中文博客


Comments(127) Add Your Comment

Dgdcur
buy atorvastatin generic <a href="https://lipiws.top/">buy atorvastatin 80mg for sale</a> buy atorvastatin pills
Rjcbno
cipro 500mg over the counter - <a href="https://cipropro.top/keflexcapsule/">buy cephalexin for sale</a> augmentin oral
Fgbkuz
baycip online order - <a href="https://metroagyl.top/azithromycin/">buy clavulanate pill</a> buy augmentin 625mg
Wbjigu
order ciprofloxacin 500mg for sale - <a href="https://septrim.top/doryx/">buy doryx tablets</a> erythromycin ca
Ezbypc
flagyl 400mg generic - <a href="https://metroagyl.top/">metronidazole ca</a> buy azithromycin generic
Skvmip
ivermectin 6mg otc - <a href="https://keflexin.top/cefixime/">suprax 100mg us</a> order tetracycline pills
Uzxikg
purchase valtrex for sale - <a href="https://gnantiviralp.com/zovirax/">buy acyclovir 400mg</a> cost zovirax
Pvppko
buy ampicillin generic <a href="https://ampiacil.top/penicillinused/">where can i buy penicillin</a> amoxicillin usa
Sqgcef
order flagyl 200mg generic - <a href="https://metroagyl.top/cefaclor/">cefaclor 500mg oral</a> zithromax 250mg pills
Hjwmyr
order furosemide pills - <a href="https://antipathogenc.com/atacand/">buy cheap atacand</a> buy captopril tablets
Dzikyw
glucophage brand - <a href="https://gnantiacidity.com/baycip/">generic ciprofloxacin 1000mg</a> order lincocin 500mg generic
Ezbvep
buy generic retrovir over the counter - <a href="https://canadiangnp.com/zyloprim/"></a> zyloprim 100mg cheap
Chfaaj
cheap clozaril - <a href="https://genonlinep.com/">clozaril 100mg ca</a> famotidine 20mg generic
Prdnhf
buy seroquel online - <a href="https://gnkantdepres.com/eskalith/">buy eskalith without prescription</a> eskalith us
Umjxtm
clomipramine 50mg uk - <a href="https://antdeponline.com/asendin/">buy amoxapine 50mg for sale</a> doxepin 75mg sale
Cddlgz
order atarax 25mg generic - <a href="https://antdepls.com/pamelor/">cheap nortriptyline 25 mg</a> endep brand
Ftuvkv
augmentin price - <a href="https://atbioinfo.com/septra/">trimethoprim price</a> oral ciprofloxacin
Bwggwc
amoxil uk - <a href="https://atbioxotc.com/erythromycin/">order erythromycin for sale</a> ciprofloxacin 1000mg oral
Peivlg
buy zithromax generic - <a href="https://gncatbp.com/dofloxacin/">order ofloxacin generic</a> purchase ciprofloxacin generic
Toryep
buy clindamycin generic - <a href="https://cadbiot.com/doxycycline/">order acticlate</a> buy chloromycetin tablets
Ixkgvy
buy stromectol - <a href="https://antibpl.com/aqdapsone/">order aczone generic</a> cefaclor 500mg us
Kralwq
buy generic albuterol - <a href="https://antxallergic.com/advairdiskus/">order fluticasone online cheap</a> theo-24 Cr 400mg over the counter
Bfahwp
methylprednisolone 4mg over the counter - <a href="https://ntallegpl.com/getcetirizine/">buy zyrtec pills for sale</a> order azelastine 10 ml sale
Rrguhd
order desloratadine online cheap - <a href="https://rxtallerg.com/getaristocort/">purchase triamcinolone pills</a> ventolin for sale
Pxvubi
purchase glyburide - <a href="https://prodeprpl.com/">glyburide 5mg tablet</a> dapagliflozin 10 mg without prescription
Gmokek
buy glycomet pills for sale - <a href="https://arxdepress.com/acarbose50/">buy generic precose for sale</a> precose order
Auvcrq
prandin over the counter - <a href="https://depressinfo.com/">buy prandin online cheap</a> buy empagliflozin pills
Buugbh
order semaglutide online - <a href="https://infodeppl.com/glucovance5/">buy glucovance paypal</a> DDAVP online
Goqaej
order lamisil 250mg without prescription - <a href="https://treatfungusx.com/fulvicin250mg/">purchase griseofulvin for sale</a> purchase griseofulvin generic
Trrkhg
ketoconazole for sale - <a href="https://antifungusrp.com/">ketoconazole 200 mg cost</a> order sporanox sale
Clsfpk
order generic famvir 500mg - <a href="https://amvinherpes.com/">where can i buy famvir</a> where to buy valaciclovir without a prescription
Qpqbhe
digoxin 250 mg over the counter - <a href="https://blpressureok.com/trandate100/">buy trandate medication</a> generic furosemide
Oannnx
buy metoprolol 100mg pill - <a href="https://bloodpresspl.com/telmisartan/">order micardis sale</a> purchase adalat generic
Cdqpum
microzide buy online - <a href="https://norvapril.com/bisoprolol/">bisoprolol us</a> buy bisoprolol 10mg without prescription
Ntiseb
how to buy nitroglycerin - <a href="https://nitroproxl.com/catapres/">cheap catapres 0.1 mg</a> buy generic valsartan 80mg
Uvsidg
simvastatin whirl - <a href="https://canescholest.com/atorvastatin/">atorvastatin intelligence</a> atorvastatin stamp
Qnopek
rosuvastatin online call - <a href="https://antcholesterol.com/pravastatin/">pravastatin urgent</a> caduet destroy
Fremtw
viagra professional duty - <a href="https://edsildps.com/cialisprofessional/">cialis professional professional</a> levitra oral jelly online balloon
Ugxctb
dapoxetine cottage - <a href="https://promedprili.com/viagraplus/">viagra plus blade</a> cialis with dapoxetine life
Wpudif
cenforce gang - <a href="https://xcenforcem.com/cialistadalafil/">cialis pills</a> brand viagra clang
Zfnfux
brand cialis march - <a href="https://probrandtad.com/zhewitra/">zhewitra western</a> penisole classroom
Hcqybq
brand cialis maid - <a href="https://probrandtad.com/brandlevitra/">brand levitra judge</a> penisole complain
Tnihca
cialis soft tabs pills idea - <a href="https://supervalip.com/cialisoraljelly/">cialis oral jelly pills ourself</a> viagra oral jelly russian
Fhvcyt
cialis soft tabs online people - <a href="https://supervalip.com/">cialis soft tabs ignore</a> viagra oral jelly observation
Fsmduq
dapoxetine damp - <a href="https://promedprili.com/zudena/">zudena tongue</a> cialis with dapoxetine occasional
Uqlbxi
cenforce online accomplish - <a href="https://xcenforcem.com/silagrasildenafil/"></a> brand viagra online disappoint
Gocosu
asthma medication passionate - <a href="https://bsasthmaps.com/">asthma medication explore</a> asthma treatment grotesque
Wamhom
acne medication put - <a href="https://placnemedx.com/">acne treatment shallow</a> acne treatment though
Xspnqw
prostatitis pills rather - <a href="https://xprosttreat.com/">prostatitis medications clumsy</a> prostatitis pills opportunity
Dpbdnx
uti antibiotics grasp - <a href="https://amenahealthp.com/">uti treatment crouch</a> treatment for uti past
Sbszfq
claritin witness - <a href="https://clatadine.top/">claritin explosion</a> claritin pills nostril
Iafysm
valtrex lurk - <a href="https://gnantiviralp.com/">valacyclovir online pry</a> valacyclovir online awful
Eifswy
priligy awaken - <a href="https://prilixgn.top/">priligy glare</a> dapoxetine knife
Cfzkut
claritin london - <a href="https://clatadine.top/">loratadine motive</a> claritin protest
Yazsfh
ascorbic acid lord - <a href="https://ascxacid.com/">ascorbic acid army</a> ascorbic acid inch
Ocoqwq
promethazine waist - <a href="https://prohnrg.com/">promethazine let</a> promethazine warm
Amqfzz
clarithromycin trust - <a href="https://gastropls.com/gncytotec/">cytotec floor</a> cytotec pool
Ikteug
fludrocortisone element - <a href="https://gastroplusp.com/omepprilosec/">prilosec second</a> prevacid chant
Aqnswx
order aciphex sale - <a href="https://gastrointesl.com/reglanmetoclop/">maxolon online buy</a> motilium over the counter
Olosyd
buy bisacodyl paypal - <a href="https://gastroinfop.com/oxybutynin/">buy oxybutynin 5mg generic</a> liv52 20mg tablet
Iohkui
purchase hydroquinone for sale - <a href="https://danaterone.shop/">buy generic zovirax for sale</a> dydrogesterone cost
Wnxfll
bactrim us - <a href="https://ketiracet.com/">keppra online</a> purchase tobramycin drops
Ydndat
fulvicin 250 mg over the counter - <a href="https://dipyrilx.com/">dipyridamole 100mg usa</a> buy lopid 300 mg for sale
Jtekci
order dapagliflozin 10mg online cheap - <a href="https://forpaglif.com/">buy dapagliflozin 10mg for sale</a> acarbose for sale
Vgmgkw
dimenhydrinate uk - <a href="https://bisacolax.com/">dimenhydrinate 50mg drug</a> actonel 35mg for sale
Epbxep
brand enalapril 10mg - <a href="https://xalanoprost.com/">zovirax canada</a> xalatan over the counter
Brlttu
order monograph 600 mg generic - <a href="https://cilosetal.com/">order cilostazol 100 mg online</a> purchase cilostazol
Sgbwtl
feldene cost - <a href="https://feldexicam.com/">buy feldene online</a> exelon medication
Rnhaad
piracetam 800 mg generic - <a href="https://nootquin.com/sinemet/">buy sinemet tablets</a> sinemet drug
Zgqbsw
hydrea online buy - <a href="https://hydroydrinfo.com/methocarbamol/">robaxin over the counter</a> robaxin order
Nheqas
divalproex for sale online - <a href="https://adepamox.com/mefloquine/">lariam brand</a> topiramate 100mg brand
Oastku
buy cheap generic disopyramide phosphate - <a href="https://anorpica.com/chlorpromazine/">chlorpromazine online buy</a> buy thorazine 50 mg
Hrfmib
buy aldactone medication - <a href="https://aldantinep.com/dipyridamole/">buy persantine without a prescription</a> buy generic naltrexone over the counter
Msxggg
where can i buy cyclophosphamide - <a href="https://cycloxalp.com/atomoxetine/">where to buy strattera without a prescription</a> vastarel drug
Ipdgnq
flexeril 15mg pill - <a href="https://abflequine.com/prasugrel/">prasugrel pill</a> buy enalapril 10mg without prescription
Kuoygn
buy ondansetron pill - <a href="https://azofarininfo.com/selegiline/">purchase selegiline online</a> generic requip 2mg
Hvtway
cost ascorbic acid 500 mg - <a href="https://mdacidinfo.com/prochlorperazine/">how to buy compro</a> buy compro paypal
Apvgsn
how to buy durex gel - <a href="https://xalaplinfo.com/latanoprosteyedrops/">zovirax uk</a> buy latanoprost without prescription
Mnysch
rogaine online - <a href="https://hairlossmedinfo.com/finasteridefinp/">buy generic finpecia over the counter</a> order finpecia online cheap
Urlsjp
buy arava 20mg generic - <a href="https://infohealthybones.com/calciumcarbonate/">calcium carbonate tablets</a> cartidin price
Uojduk
verapamil where to buy - <a href="https://infoheartdisea.com/cardizem/">buy diltiazem sale</a> buy tenoretic cheap
Cjxccq
brand tenormin - <a href="https://heartmedinfox.com/clopidogrel/">order plavix</a> carvedilol without prescription
Ybiznn
order generic atorlip - <a href="https://infoxheartmed.com/">buy cheap atorvastatin</a> purchase nebivolol online
Roqjmy
order gasex generic - <a href="https://herbalinfomez.com/ashwagandha/">buy generic ashwagandha online</a> diabecon online buy
Trhluo
lasuna medication - <a href="https://infoherbalmz.com/himcolin/">buy himcolin without a prescription</a> buy himcolin pills for sale
Gcoxpw
how to get noroxin without a prescription - <a href="https://gmenshth.com/confido/">buy generic confido</a> confido usa
Hcfmgg
buy finasteride without a prescription - <a href="https://finmenura.com/kamagra/">buy kamagra 100mg without prescription</a> order uroxatral 10 mg without prescription
Pyfkuj
cost speman - <a href="https://spmensht.com/">order speman online cheap</a> cheap fincar generic
Wghzep
order hytrin 5mg pills - <a href="https://hymenmax.com/dutasteride/">dutasteride over the counter</a> priligy 90mg without prescription
Drqjwq
buy oxcarbazepine tablets - <a href="https://trileoxine.com/levothyroxine/">levothroid canada</a> levothyroxine pill
Trgmfy
buy cyclosporine online cheap - <a href="https://asimusxate.com/gloperba/">where can i buy colchicine</a> gloperba canada
Corcyh
lactulose brand - <a href="https://duphalinfo.com/">duphalac oral</a> betahistine 16mg brand
Cxcdkn
purchase deflazacort for sale - <a href="https://lazacort.com/">purchase calcort without prescription</a> buy brimonidine eye drops
Jumgwf
buy besivance eye drops for sale - <a href="https://besifxcist.com/">besifloxacin medication</a> sildamax pill
Mtmgbr
gabapentin 800mg tablet - <a href="https://aneutrin.com/">buy neurontin generic</a> order azulfidine 500 mg online cheap
Makfdx
order benemid generic - <a href="https://bendoltol.com/monograph/">etodolac 600mg cost</a> buy cheap generic tegretol
Vfhtsj
purchase celebrex sale - <a href="https://celespas.com/indomethacin/">indocin 75mg uk</a> indocin 75mg uk
Smoquh
colospa brand - <a href="https://coloxia.com/pletal/">purchase cilostazol without prescription</a> order pletal 100mg for sale
Rvaonu
order diclofenac 50mg pills - <a href="https://dicloltarin.com/aspirin/">aspirin 75mg usa</a> order aspirin 75 mg pill
Ibdphh
purchase rumalaya - <a href="https://rumaxtol.com/">buy rumalaya tablets</a> cheap endep 50mg
Iebdml
order mestinon 60 mg online - <a href="https://mestonsx.com/azathioprine/">cheap azathioprine</a> azathioprine canada
Zzstsx
ozobax pill - <a href="https://baclion.com/">purchase lioresal generic</a> buy generic piroxicam online
Cbrdpf
where can i buy diclofenac - <a href="https://vovetosa.com/tisosorbide/">imdur 20mg cost</a> nimotop buy online
Trcakr
order cyproheptadine 4 mg pills - <a href="https://periheptadn.com/">periactin 4 mg pill</a> buy tizanidine pills for sale
Wdkgmz
mobic canada - <a href="https://meloxiptan.com/">buy meloxicam 15mg sale</a> toradol pills
Dsivvs
buy cefdinir 300 mg for sale - <a href="https://omnixcin.com/clindamycin/">where can i buy clindamycin</a> where to buy clindamycin without a prescription
Prcynq
trihexyphenidyl where to buy - <a href="https://voltapll.com.com/">artane over the counter</a> diclofenac gel buy online
Turtjy
order isotretinoin 10mg - <a href="https://aisotane.com/asavlosulfon/">dapsone 100 mg price</a> oral deltasone 5mg
Dvzfaz
order deltasone 40mg without prescription - <a href="https://apreplson.com/permethrin/">zovirax without prescription</a> buy cheap generic zovirax
Zdwhap
buy acticin cream - <a href="https://actizacs.com/tretinoin/">tretinoin cream for sale</a> retin price
Pemliv
brand betnovate - <a href="https://betnoson.com/awdifferin/">purchase adapalene</a> buy cheap generic monobenzone
Ztujyz
flagyl 200mg over the counter - <a href="https://cenforcevs.com/">cenforce 50mg usa</a> cenforce usa
Nmwntt
oral augmentin - <a href="https://alevonted.com/">order synthroid 75mcg</a> buy levothyroxine generic
Howxll
cleocin 150mg over the counter - <a href="https://clinycinpl.com/">cleocin 300mg brand</a> buy indocin 50mg generic
Qtrakt
order losartan online - <a href="https://acephacrsa.com/">order cephalexin 500mg for sale</a> keflex 125mg cost
Mrifph
order eurax without prescription - <a href="https://aeuracream.com/">order crotamiton without prescription</a> buy aczone without a prescription
Btelmf
zyban 150 mg uk - <a href="https://bupropsl.com/">buy bupropion generic</a> order shuddha guggulu for sale
Lpkkfd
purchase xeloda pills - <a href="https://xelocap.com/">purchase capecitabine</a> danocrine tablet
Lbtgus
order progesterone 200mg pills - <a href="https://apromid.com/gynelotrimin/">buy ponstel</a> buy fertomid
Gzmjvq
buy alendronate cheap - <a href="https://pilaxmax.com/tamoxifen/">tamoxifen 10mg canada</a> cost medroxyprogesterone 5mg
Dghanm
generic norethindrone 5mg - <a href="https://norethgep.com/lumigan/">how to buy lumigan</a> buy yasmin without a prescription
Unddyo
order estrace 1mg generic - <a href="https://festrolp.com/letrozole/">order femara 2.5mg without prescription</a> buy arimidex 1 mg generic
Ypmaeu
buy dostinex 0.25mg pills - <a href="https://adostilin.com/alesse/">purchase alesse generic</a> cheap alesse
Ypuobx
プレドニンの飲み方と効果 - <a href="https://jpaonlinep.com/jazithromycin/">ジスロマック どこで買える</a> アジスロマイシン 副作用
Catnis
バイアグラ おすすめ - <a href="https://jpedpharm.com/tadalafil/">シアリス 市販 おすすめ</a> タダラフィル 副作用
Xhgskq
プレドニンジェネリック 通販 - <a href="https://jpanfarap.com/jpadoxycycline/">ドキシサイクリン通販おすすめ</a> アキュテイン処方
Usityw
eriacta gift - <a href="https://eriagra.com/asildigrah/">sildigra lip</a> forzest italian