我正在尝试从用户那里获取所有 3 个输入,单击该按钮会将它们带到下一页。我已经创建了一个 if-else
语句来检查 3 个输入字段并且它有效。但是当我单击该按钮时,它不会将我带到下一个或 URL。
function calcBody()
{
var b=document.forms["input"]["bust"].value;
var w=document.forms["input"]["waist"].value;
var h=document.forms["input"]["hips"].value;
if (b == null || b == "", w == null || w == "", h == null || h == "")
{
alert("Please Fill All Required Field");
}
else
{
window.location = "http://www.google.com";
}
}
最佳答案
阻止您的表单提交,例如:
<input id="bigbutton" type="submit" value="Go to recommendation" onClick="return calcBody()"/>
在你的脚本中
function calcBody()
{
var b=document.forms["input"]["bust"].value;
var w=document.forms["input"]["waist"].value;
var h=document.forms["input"]["hips"].value;
if (b == null || b == "", w == null || w == "", h == null || h == "")
{
alert("Please Fill All Required Field");
}
else
{
window.location.href = "http://www.google.com";
}
return false
}
或者
更改您的输入类型提交到按钮
<input id="bigbutton" type="button" value="Go to recommendation" onClick="return calcBody()"/>
关于javascript - 验证 3 个输入字段后按钮不会将我带到下一个 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26172902/