【发布时间】:2016-06-02 12:39:00
【问题描述】:
我正在尝试在多个目录的页面之间切换,我目前的做法是正确的,但是一旦我有 +300 个 HTML 页面,我就不能这样了:
window.addEventListener('load', leftNav, false);
var x = location.pathname;
alert(x);
function leftNav() {
appendUl('leftNav', 'outerUL');
appendLiA('outerUL', 'offers', '/Ofertas/offers.html', 'Offers');
appendLiA('outerUL', 'mobilecarriers', '/Ofertas/mobilecarriers.html', 'Mobile Carriers');
appendLiA('outerUL', 'affilpixeltracking', '/Ofertas/affiliatepixel.html', 'Affiliate Pixel Tracking');
appendLiA('outerUL', 'carrierip', '/Ofertas/carrierip.html', 'Carrier IP');
appendLiA('outerUL', 'updtconverstats', '/Ofertas/Pag1.html', 'Update Conversion Status');
appendLiA('outerUL', 'updtconverstats2', '/Ofertas/Pag4.html', 'Update Conversions Status - S2');
appendLiA('outerUL', 'getconvdata', '/Ofertas/Pag2.html', 'Get Conversions Data');
appendLiA('outerUL', 'getconvdata2', '/Ofertas/Pag6.html', 'Get Conversion Data - S2');
appendLiA('outerUL', 'updtconverspr', '/Ofertas/Pag3.html', 'Update Conversions P/R');
appendLiA('outerUL', 'updtconverpr2', '/Ofertas/Pag5.html', 'Update Conversions P/R - S2');
appendLiA('outerUL', 'test', '/teste/index.html', 'Test');
function appendUl(append_to_id, ul_id) {
var ul = document.createElement('ul');
ul.id = ul_id;
var appendTo = document.getElementById(append_to_id);
appendTo.appendChild(ul);
}
function appendLiA(append_to_id, li_id, a_href, a_text, i_class) {
var a = document.createElement('a');
a.href = a_href;
a.textContent = a_text;
var li = document.createElement('li');
li.id = li_id;
li.appendChild(a);
var appendTo = document.getElementById(append_to_id);
appendTo.appendChild(li);
}
}
在页面的href中,例如:“/Ofertas/offers.html”,我希望它动态获取页面的目录,我在开始时使用location.pathname。但是现在,我希望它在页面之间切换时动态插入到那个地方。有人知道怎么做吗?
【问题讨论】:
标签: javascript html netbeans directory