数か月前、サイドバーを毎年新しいリンクで更新する必要があることに気付きました。ここで、各ページを調べてリンクを挿入する (約 20 ページ) 代わりに、javascript ファイルを作成して各ページにリンクすることにしました。スクリプトはリンクを作成し、ページに追加します。つまり、新しいリンクを作成する必要があるたびに、javascript ファイルに新しい行を 1 回追加するだけで、変更が各ページに反映されます。基本的に、すべてのページを調べて新しいリンクを追加する無駄な時間を削減します。これは良い習慣なのか、私が予測できなかった問題があるのでしょうか?
コードを以下に示します。
function createVolume (text, link){
var volDiv = document.createElement("div");
var textDiv = document.createTextNode(text);
var linkDiv = document.createElement("a");
linkDiv.setAttribute("href", link);
volDiv.setAttribute("class", "volume");
volDiv.appendChild(textDiv);
linkDiv.appendChild(volDiv);
var d = document.getElementById("e27");
d.appendChild(linkDiv);
}
var bhbHome = createVolume("BHB Home", "bhb.html");
var v76 = createVolume("Volume 76", "bhb76.html");
var v75 = createVolume("Volume 75", "bhb75.html");
var v74 = createVolume("Volume 74", "bhb74.html");
var v73 = createVolume("Volume 73", "bhb73.html");
var v72 = createVolume("Volume 72", "bhb72.html");
var v71 = createVolume("Volume 71", "bhb71.html");
var v70 = createVolume("Volume 70", "bhb70.html");
var v69 = createVolume("Volume 69", "bhb69.html");
var v68 = createVolume("Volume 68", "bhb68.html");
var v67 = createVolume("Volume 67", "bhb67.html");
var v6566 = createVolume("Volume 65 and 66", "bhb_65_66.html");
var v64 = createVolume("Volume 64", "bhb64.html");
var v63 = createVolume("Volume 63", "bhb63.html");
var v626160 = createVolume("Volume 60, 61, and 62", "bhb_60_61_62.html");
var v59 = createVolume("Volume 59","bhb59.html");