表单上有一个"is"或“否”字段,具体取决于用户的选择,我想根据他们的回答将他们发送到不同的感谢页面。
有了这个,我只得到一个空白页。我已经尝试了我能想到的一切,所以我很感激任何见解。
<form action="http://www.google.com/form" name="Lead" id="Lead" class="sem-form" onsubmit="return redirectTY()">
<label class="select">
<select name="Invest_RD" id="Invest_RD">
<option value="Yes">Yes</option>
<option selected="selected" value="No">No</option>
</select>
</label>
</form>
function redirectTY(){
var qualify = document.getElementById("Invest_RD".value);
if (qualify == "Yes"){
window.location.href='http://www.google.com';
} else {
window.location.href='http://www.bing.com';
}
}
最佳答案
您的代码看起来不错,除了以下细节:
document.getElementById("Invest_RD".value);
这会让你所有的 JavaScript 崩溃。可能您的控制台(开发人员工具)有与此相关的红色消息。要修复它,请写入:
document.getElementById("Invest_RD").value;
这是因为 getElementById()
是 document
的方法,而 value
是 getElementById() 返回的元素的属性)
。
关于Javascript 重定向到两个感谢页面,具体取决于表单响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39599171/