voithosと同じですが、jQueryのなし:機能で
var links=document.links; //Get all links in the document
for (var i=0;i<links.length;i++) { //Loop through each link
thisHrefExt=links[i].href.split("."); //Split target at all periods
thisHrefExt=thisHrefExt[thisHrefExt.length-1]; //Select the last section, which should be the extension
if (thisHrefExt.toLowerCase()=="pdf") { //If the extension is "pdf" (case insensitive)...
links[i].href="hard-coded-front-end"+links[i].href; //...Add your hard-coded bit at the beginning
}
}
形式:
01:機能付き
function changePDFLinks() {
var links=document.links; //Get all links in the document
for (var i=0;i<links.length;i++) { //Loop through each link
thisHrefExt=links[i].href.split("."); //Split target at all periods
thisHrefExt=thisHrefExt[thisHrefExt.length-1]; //Select the last section, which should be the extension
if (thisHrefExt.toLowerCase()=="pdf") { //If the extension is "pdf" (case insensitive)...
links[i].href="hard-coded-front-end"+links[i].href; //...Add your hard-coded bit at the beginning
}
}
}
、あなたはこのような何かを行うことができます
window.onload=changePDFLinks;
ページが読み込まれたときにPDFリンクを修正します。
これは素晴らしいです。これを.jsファイルに入れて、それを複数のファイルで実行できるようにすることはできますか? –
確かに、機能フォーム(編集された回答)onloadを使用してください。 –