所以这会一直有效,直到它尝试填充URL。警报显示值(小写),但是当填充URL时,它使用选项的innertext(大写)。
理想情况下,我希望选项类似于此
<option value="pdf">PDF - printable, viewable</option>
我知道应该有一种方法让它动态创建URL而不是通用的“主页”链接,然后替换它但是我尝试过的无数东西都不起作用,因为代码试图重写尚未创造的东西。我真的不想与DOM一起工作,从我的研究似乎是做这件事的唯一方法。
我想要的另一件事是能够以模态执行此操作。但是当我把它放在一个时,单击链接后关闭功能不起作用。那是因为它不再是活动窗口吗?这不是什么大问题,我已经在这里找到了很多代码,但是如果你想看到它,请告诉我。
<form>
Select the year:
<select id="myYear">
<option>2018</option>
<option>2017</option>
<option>2016</option>
<option>2015</option>
</select>
<br><br>
Select the month:
<select id="myMonth">
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<br><br>
Select Calendar or Article:
<select id="myType">
<option>Article</option>
<option>Calendar</option>
</select>
<br><br>
Select PDF, Word or Webpage:
<select id="myFormat">
<option value="pdf">PDF</option>
<option value="doc">DOC</option>
<option value="htm">HTM</option>
</select>
<br><br>
<input type="button" onclick="myFunction()" value="Click Me!">
<br><br>
</form>
<a id="myLink" href="http://www.myOrgn.org/Article/April 2017
Article.pdf" target="_blank">Article Homepage and Submission</a>
</div>
</div>
<script>
function myFunction() {
var Yrsel = document.getElementById("myYear");
var Mnthsel = document.getElementById("myMonth");
var Typesel = document.getElementById("myType");
var Formatsel = document.getElementById("myFormat");
var Formatsel1 = Formatsel.value;
alert(Formatsel1);
document.getElementById("myLink").innerHTML = "Get Link";
if (Typesel.options[Typesel.value] = "Article") {
document.getElementById("myLink").href =
"http://www.myOrg.org/Article/" +
Mnthsel.options[Mnthsel.selectedIndex].text + " " +
Yrsel.options[Yrsel.selectedIndex].text + " Article" +
Typesel.options[Typesel.selectedIndex].text + "." +
Formatsel.value;
}
if (Typesel.options[Typesel.value] = "Calendar") {
document.getElementById("myLink").href =
"http://www.myOrg.org/Article/" +
Mnthsel.options[Mnthsel.selectedIndex].text + " " +
Yrsel.options[Yrsel.selectedIndex].text + " " +
Typesel.options[Typesel.selectedIndex].text + "." +
Formatsel.options[Formatsel.selectedIndex].text;
}
}
</script>
新的Javascript代码
<script>
function myFunction() {
var Yrsel = document.getElementById("myYear");
var Mnthsel = document.getElementById("myMonth");
var Typesel = document.getElementById("myType");
var Formatsel = document.getElementById("myFormat");
var LinkUrl = Mnthsel.value + " " + Yrsel.value + " Article." +
Formatsel.value;
var LinkUrl2 = Mnthsel.value + " " + Yrsel.value + "." +
Formatsel.value;
if (Typesel.options[Typesel.selectedIndex].text == "Article") {
document.getElementById("myLink").href =
"http://www.myOrg.org/Article/" + LinkUrl;
document.getElementById("myLink").innerHTML = "Get Article";
}
if (Typesel.options[Typesel.selectedIndex].text == "Calendar" &&
Formatsel.value == "doc") {
document.getElementById("myLink").href =
"http://www.myOrg.org/Article/Calendar for " + LinkUrl2 + "x";
document.getElementById("myLink").innerHTML = "Get Calendar";
}
else {
document.getElementById("myLink").href =
"http://www.myOrg.org/Article/Calendar for " +
LinkUrl2;
document.getElementById("myLink").innerHTML = "Get Calendar";
}
}
</script>
答案 0 :(得分:1)
两个问题。
=
进行比较
实际执行任务。dropDownMenu/<Select>
获取所选值
.value
就可以了。