gpt4 book ai didi

javascript - 尝试动态更改 anchor HREF

转载 作者:行者123 更新时间:2023-12-03 12:17:00 25 4
gpt4 key购买 nike

我有一个网站,其中包含许多内部报告,这些报告每周都会从各种来源更新,并且每年我们都会存档年终版本。因此,我们在服务器上有一个如下所示的文件夹结构:

Department
Current
report1
report2
<etc.>
2013
report1
report2
<etc.>
2012
<etc.>

我创建了一个选择,让用户可以选择所需的时间段:

<select id="period" onchange="UpdateLinks(this)">
<option value="current" selected>Current</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
</select>

实际链接定义为:

<a onclick="EnablePrint();" href="Offshore\Current\NYK_Offshore_Summary.htm" 
id="offshoreSales" TARGET="report">Sales</a><br>

请注意,该网站位于两个框架中 - 这些项目显示在“菜单”侧,报告显示在“报告”侧(如果相关)。

在 UpdateLinks() 中,我尝试更新 anchor 中的 href 以指向适当的文件夹。根据这里的一些条目,这应该有效,但它对我不起作用!:

function UpdateLinks(selected) {
var myURL = 'Offshore\\' + selected.value + '\\';
alert('New URL prefix: ' + myURL);
var newURL = myURL + 'NYK_Offshore_Summary.htm';
document.getElementByID('offshoreSales').href = newUrl;
newURL = myURL + 'NYK_Offshore_Assets.htm';
document.getElementByID('offshoreAssets').href = newURL;
}

alert() 正在发生,并且我看到了正确的值 - 例如“当前”或“2013”​​,但这些行

document.getElementByID('offshoreSales').href = newUrl;

不是。我错过了什么?

最佳答案

输入错误:

document.getElementByID('offshoreSales').href = newUrl;

尝试:

document.getElementById('offshoreSales').href = newUrl;

关于javascript - 尝试动态更改 anchor HREF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24637033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com