【发布时间】:2015-03-03 09:48:07
【问题描述】:
我用过 jquery-1.11.2.min.js 和 chrome 40.0.2214.115
在用户注册表单中,如果任何字段为空,我想向用户显示警报消息,否则重定向到 servlet 类文件,在该 servlet 类中,我编写了用于插入用户详细信息的 db 连接。
我的用户注册html代码是
<script type="text/javascript" src="js/plugins/jquery-1.11.2.min.js"></script>
<script>
$(document).ready(function()
{
$("#submitid").click(function()
{
var fname=$("#firstname2").val();
var lanme=$("#lastname2").val();
var email=$("#email2").val();
var mobileno=$("#mobileno").val();
var username=$("#username").val();
var pass=$("#password").val();
if(fname==''||lname==''||email=''||mobileno==''||username==''||pass=='')
{
alert("Enter all fields");
$("#userform").focus();
}
else
window.location.href("Userdetailsins.java");
});
});</script>
</head>
<body>
<form class="stdform stdform2" method="post" id="userform">
<label>First Name</label>
<input type="text" name="userfname" id="firstname2" class="longinput" />
<label>Last Name</label>
<input type="text" name="userlname" id="lastname2" class="longinput" />
<label>Email</label>
<input type="text" name="mailid" id="email2" class="longinput"
<label>Mobile no</label>
<input type="text" name="mobno" id="mobileno" class="longinput"
<label>User name </label>
<input type="text" name="username" id="username" class="longinput" />
<label>User Password </label>
<input type="password" name="password" id="password" class="longinput" /></span>
<input type="reset" value="Reset Button" />
<input type="submit" id="submitid" name="submitid" value="Next"/>
</form>
</body>
</html>
当字段为空并且不重定向到另一个表单时,它不会显示警报消息。即使我尝试使用另一个 html 文件来重定向它也不起作用。对于重定向,我遵循了如下所示的准则
//$(location).attr('href',"http://www.google.com");
//window.open("next.html");
//$("#submitform").focus();
//$(window.location).attr('href', 'http://www.google.com');
//window.navigator("next.html");
//self.location="next.html";
//top.location="next.html";
//var url="www.google.com"
//window.location.replace(url);
//window.location.href("next.html");
window.open("next.html");
window.open() 方法有效,但我不想作为单独的窗口打开,我只是为了重定向。请任何人帮助解决这个问题。
谢谢....
【问题讨论】:
-
通过使用这个你得到任何错误 window.location.href("next.html"); @Asha
-
Thanks@coding cracker 我没有收到任何错误。位于同一页面上的表单未重定向到 next.html。
-
点击后你需要重定向到另一个页面吗?
-
试试我的答案,它会起作用的:)