我希望在验证表单中的所有字段后重定向到另一个页面。我在CSS中这样做。我希望在CSS中验证后触发重定向方法。
我在网上看到我们可以使用:
window.location = "https://www.asdfg.com" //Something like this
<style>
div.selectBox
{position:relative;display:inline-block;cursor:default;
text-align:left;lineheight:30px;clear:both;color:#888;}
span.selected
{width:167px;text-indent:20px;border:1px solid #ccc;border-right:none;border-top-left-radius:5px;
border-bottom-left-radius:5px;background:#FFFFFF;overflow:hidden;}
span.selectArrow
{width:30px;border:1px solid #FFFFFF;border-top-right-radius:4px;border-bottom- right-radius:4px;
text-align:center;font-size:20px;-webkit-user-select: none;-khtml-user-select: none;
-moz-user-select: none; -o-user-select: none;user-select: none;background:#FFFFFF;}
span.selectArrow,span.selected
{位置:相对;浮动:左;高度:30像素; z索引:1;}
div.selectOptions
{position:absolute;top:28px;left:0;width:198px;border:1px solid #ccc;border-bottom- right-radius:5px;
border-bottom-left-radius:5px;overflow:hidden;background:#FFFFFF;padding-top:2px;display:none;}
span.selectOption
{display:block;width:80%;line-height:20px;padding:5px 10%;}
span.selectOption:hover
{color:#ffffff; background:#4096ee;}
</style>
<body>
<h1>Registration form</h1>
<form id=payment>
<fieldset>
<legend>Account Information</legend>
<ol>
<li><input id=name name=name size="40" type=text placeholder="User Name" required autofocus></li>
<li><input id=email name=email type=email placeholder="Password" required></li>
<li><input id=phone name=phone type=tel placeholder="Verify Password" required></li>
</ol>
</fieldset>
<fieldset>
<legend>User Details</legend>
<ol>
<li><input id=name name=name type=text placeholder="First Name" required autofocus> </li>
<li><input id=name name=name type=text placeholder="Last Name" required autofocus></li>
<li><input id=name name=name type=text placeholder="Email ID" required autofocus></li>
<li><input id=email name=email type=email placeholder="Company" required></li>
<li><input id=phone name=phone type=tel placeholder="Telephone No" required></li>
</div>
</li>
<li>
<button type=submit>Register</button>
</fieldset>
</form>
</section>
</div>
</body>
答案 0 :(得分:0)
你的意思是
HTML:
<input type="button" id="registerbutton" value="Register" />
JS:
$("#registerbutton").click(function () { register(); });
function register() {
$("#myform").validate();
if ($("#myform").valid()) {
window.location = 'http://stackoverflow.com/';
}
}
如果您想发布表单,我认为您必须使用$ .ajax并在成功回调时重定向。同时了解您的概念并查看焙烤的评论。