使用 jquery 重定向到 servlet class 文件
redirect to servlet class file using jquery
我用过jquery-1.11.2.min.js和chrome40.0.2214.115
在用户注册表中,如果任何字段为空,我想向用户显示警告消息,否则重定向到 servlet class 文件,在那个 servlet class 中,我写了数据库连接用于插入用户详细信息。
我的用户注册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 打开,我只是为了重定向。请任何人帮助解决这个问题。
谢谢....
使用这个
function nextredirect(){
window.location.href = 'next.html';
}
Jquery
$('#submitid').click(function(){
if($('#firstname2').val() == ""){
alert('Please enter the first name');
}else{
window.location.href = 'next.html';
}
});
Html
<input type="button" id="submitid" name="submitid" value="Next" onclick="nextredirect()"/>
我用过jquery-1.11.2.min.js和chrome40.0.2214.115
在用户注册表中,如果任何字段为空,我想向用户显示警告消息,否则重定向到 servlet class 文件,在那个 servlet class 中,我写了数据库连接用于插入用户详细信息。
我的用户注册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 打开,我只是为了重定向。请任何人帮助解决这个问题。
谢谢....
使用这个
function nextredirect(){
window.location.href = 'next.html';
}
Jquery
$('#submitid').click(function(){
if($('#firstname2').val() == ""){
alert('Please enter the first name');
}else{
window.location.href = 'next.html';
}
});
Html
<input type="button" id="submitid" name="submitid" value="Next" onclick="nextredirect()"/>