JavaScript加载新页面问题

时间:2010-04-18 06:02:49

标签: javascript

我要做的是,如果用户填写表单,它将提供对新位置的访问权。

<script language="JavaScript" type="text/javascript">     
<!--     
function validateForm(theForm) {     
 var firstname = theForm.firstname.value; 
 var lastname = theForm.lastname.value;      
 var email = theForm.email.value;     
 if (firstname == "") {     
   alert("Please fill in your First Name.");     
   theForm.firstname.focus();     
   return false;     
 }   
 if (lastname == "") {     
   alert("Please fill in your Last Name.");     
   theForm.lastname.focus();     
   return false;     
 } 

 if (email == "") {     
   alert("Please fill in your email address.");     
   theForm.email.focus();     
   return false;     
 }     
 return true;     
}

我知道这部分是错的,但我不知道如何去做。任何帮助都会很好..

 if lastname=""
 if firstname=""
 if email=""
 load('www.google.com');

2 个答案:

答案 0 :(得分:3)

if (validateForm(theForm)) window.location = 'http://www.google.com';

相当于使用

if (validateForm(theForm)) window.location.href = 'http://www.google.com';

两者都有效,所以选择你喜欢哪一个。

答案 1 :(得分:0)

if lastname=""
if firstname=""
if email=""
load('www.google.com');

变为

if ((lastname == "") && (firstname == "") && (email == "")) {
    window.location = "http://www.google.com";
}