我正在尝试根据用户从下拉列表中选择的内容将我的页面重定向到不同的 url。如果用户选择“A”,则 url 是表单 action 属性中的默认 URL,但如果用户选择“B”,我想将其重定向到不同的 url。
我的问题是无论我做什么,它总是重定向到默认 URL(即 oldUrl.do),即使我从下拉列表中选择“B”。
我该怎么做才能将它指向 newUrl.do?
注意:我正在使用 Struts 1.2 并在 IE8 上对其进行测试。
我的jsp页面:
<form name="myForm" method="post" action="oldUrl.do" id="myForm">
<select name="modeOfT" id="choice"><option value="A">A</option>
<option value="A">A</option>
<option value="B">B</option>
</select>
<input type="submit" name="submitBtn" onclick="submitForm()">
</form>
Javascript函数:
function submitForm(){
var form = document.getElementById("myForm");
var mode = document.getElementById("choice");
if(mode.value == "B"){
$(form).attr("action", "newUrl.do");
}
}
以下是我尝试过的其他事情,他们仍然将我带到“oldUrl.do”:
document.location.href("newUrl.do");
window.location.href="newUrl.do";
top.location.href="newUrl.do";
parent.location.href="newUrl.do";
window.location.replace("newUrl.do");
window.location="newUrl.do";