“return false”给出一个带有“false”字样的空白页面? [英] "return false" gives a blank page with the word "false" ?

查看:108
本文介绍了“return false”给出一个带有“false”字样的空白页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好大师:


我有一个验证脚本(下面),它以某种方式搞砸了。如果

名称字段为空,我收到警告消息,然后浏览器窗口

转到带有false字样的空白文档。在上面。什么是?!?!?!


为了测试,我在第二个IF

块中注释掉了'return false;''代码,所以现在,如果Name中有值,那么我收到电子邮件的警告消息

,页面保持不变。


这里到底发生了什么,我做错了吗?顺便说一句,

提交按钮是图形。

< ********** START CODE **********>

< script语言= QUOT; JavaScript的" type =" text / javascript">

<! -

function validate(){

var x =" 0" ;;


if(document.subinfo.Name.value ==""){

alert("您必须输入您的名字。 ");

document.subinfo.Name.focus();

x.value =" 1";

return(false ); }


if(document.subinfo.Email.value =="" ||

document.subinfo.Email.value.indexOf(" @")== -1 ||

document.subinfo.Email.value.indexOf("。")== -1){

alert( 电子邮件地址无效。请重新输入。;

document.subinfo.Email.focus();

//返回false; }

x.value =" 1" ;; }


if(x.value ==" 0"){

launchwin(''thanks.html'',''确认'', ''height = 200,width = 280'');

document.subinfo.submit();

location.href =" default.html" ;; }

}

- >

< / script>


<表格行动= QUOT;至mailto:我***** @ mycompany.com" ID = QUOT; subinfo" method =" post"

name =" subinfo" enctype =" text / plain">

< input name =" Name"大小= QUOT; 24英寸; />< br />< br />

< input name =" Company"大小= QUOT; 24英寸; />< br />< br />

< input name =" Email"大小= QUOT; 24英寸; />< br />< br />

< textarea name ="评论" COLS = QUOT; 38" rows =" 5">< / textarea>< br />< br />

< a href =" javascript :validate ()">

< img src =" gfx / send.gif"命名= QUOT;送"宽度= QUOT; 42'; height =" 18"

alt =" Send Form" />

< / a>& nbsp;& nbsp;

< a href =" javascript :document。 inquiries.reset()">

< img src =" gfx / clear.gif"命名= QUOT;清零"宽度= QUOT; 42'; height =" 18"

alt =" Clear Form" />

< / a>

< / form>


< ******* ***结束代码**********>


谢谢,

Kurt

解决方案

于2006年2月15日在comp.lang.javascript中写道

Hello Gurus:

我有一个验证脚本(下面),它以某种方式搞砸了。如果
Name字段为空,我收到警告消息,然后浏览器窗口
转到一个空白文档,其中包含false字样。在上面。是什么?!?!?!

为了测试,我在第二个IF
块中注释掉了'return false;''代码,所以现在如果Name中有值然后我收到电子邮件的提醒信息
并保留页面。

这里到底发生了什么,我做错了吗?顺便说一下,
提交按钮是图形。

< ********** START CODE **********>
< script language ="的JavaScript"类型= QUOT;文本/ JavaScript的">


不使用language =" JavaScript"

<! -


不使用< ; -

函数validate(){
var x =" 0" ;;

if(document.subinfo.Name.value ==" "){
警告(您必须输入您的名字。);
document.subinfo.Name.focus();
x.value =" 1" ;;
返回(假); }


应该是:


返回false; }


但是x.value =" 1" ;;不会有用,

所以在这里删除返回false

if(document.subinfo.Email.value =="" ||
document.subinfo.Email.value.indexOf(" @")== -1 ||
document.subinfo.Email.value.indexOf("。")== -1){
警告(无效的电子邮件地址。请重新输入。);
document.subinfo.Email.focus();
//返回false; }


做得好//

x.value =" 1" ;; }

if(x.value ==" 0"){
launchwin(''thanks.html'',''确认'',''height = 200,width = 280 '');


什么是launchwin()???????????

document.subinfo.submit();
位置。 href =" default.html" ;; }
}
- >
< / script>

< form action =" mailto:my ***** @ mycompany.com" ; ID = QUOT; subinfo" method =" post"
name =" subinfo" enctype =" text / plain">
< input name =" Name"大小= QUOT; 24英寸; />< br />< br />


不使用< br />但是< br>

< input name =" Company"大小= QUOT; 24英寸; />< br />< br />
< input name ="电子邮件"大小= QUOT; 24英寸; />< br />< br />
< textarea name ="评论" COLS = QUOT; 38" rows =" 5">< / textarea>< br />< br />
< a href =" javascript :validate()" >
< img src =" gfx / send.gif"命名= QUOT;送"宽度= QUOT; 42'; height =" 18"
alt =" Send Form" />
< / a>& nbsp;& nbsp;


href =" javascript :这是一个坏主意,最好这样做:


< form onsubmit = ''validate()''...





< input src =" gfx / send.gif" type =''image''alt =" Send Form">


< a href =" javascript :document.inquiries.reset( )">
< img src =" gfx / clear.gif"命名= QUOT;清零"宽度= QUOT; 42'; height =" 18"
alt =" Clear Form" />
< / a>


在这里相同:


< img onclick =''document.inquiries.reset()''src =" gfx / clear .gif"

style =''光标:指针;''>

< / form>

< **** ******结束代码**********>

谢谢,
Kurt



-

Evertjan。

荷兰。

(请将x''es更改为我的电子邮件地址中的点数)


你好


1.更好地利用ONSUBMIT活动


2。如果你只想修改你写的内容,只需在你的

验证函数调用之后添加:void(0),就像在:


< script> ;

函数fnc1()

{

if(/ * validation ok * /)

{

//提交表格

FORM_VAR.submit();

返回true;

}

返回false;

}

< / script>

< / head>


< body>

< a href =" javascript :fnc1(); void(0);"> adsasd< / a>

< / body>

< / html>


HTH

Elias


< ku *** @ ev1.net>在消息中写道

news:11 ********************** @ z14g2000cwz.googlegr oups.com ...

你好大师:

我有一个验证脚本(下面),它以某种方式搞砸了。如果
Name字段为空,我收到警告消息,然后浏览器窗口
转到一个空白文档,其中包含false字样。在上面。是什么?!?!?!

为了测试,我在第二个IF
块中注释掉了'return false;''代码,所以现在如果Name中有值然后我收到电子邮件的提醒信息
并保留页面。

这里到底发生了什么,我做错了吗?顺便说一下,
提交按钮是图形。

< ********** START CODE **********>
< script language ="的JavaScript" type =" text / javascript">
<! -
function validate(){
var x =" 0" ;;

if( document.subinfo.Name.value ==""){
alert("您必须输入您的名字。);
document.subinfo.Name.focus();
x.value =" 1" ;;
return(false); }

if(document.subinfo.Email.value =="" ||
document.subinfo.Email.value.indexOf(" @")== -1 ||
document.subinfo.Email.value.indexOf("。")== -1){
提醒(无效的电子邮件地址。请重新输入。);
document.subinfo.Email.focus();
//返回false; }
x.value =" 1" ;; }

if(x.value ==" 0"){
launchwin(''thanks.html'',''确认'',''height = 200,width = 280'');
document.subinfo.submit();
location.href =" default.html" ;; }
}
- >
< / script>

< form action =" mailto:my ***** @ mycompany.com" ; ID = QUOT; subinfo" method =" post"
name =" subinfo" enctype =" text / plain">
< input name =" Name"大小= QUOT; 24英寸; />< br />< br />
< input name =" Company"大小= QUOT; 24英寸; />< br />< br />
< input name ="电子邮件"大小= QUOT; 24英寸; />< br />< br />
< textarea name ="评论" COLS = QUOT; 38" rows =" 5">< / textarea>< br />< br />
< a href =" javascript :validate()" >
< img src =" gfx / send.gif"命名= QUOT;送"宽度= QUOT; 42'; height =" 18"
alt =" Send Form" />
< / a>& nbsp;& nbsp;
< a href =" javascript :document.inquiries.reset()"> ;
< img src =" gfx / clear.gif"命名= QUOT;清零"宽度= QUOT; 42'; height =" 18"
alt =" Clear Form" />
< / a>
< / form>

< **********结束代码******* ***>

谢谢,
Kurt



Evertjan。写道:

< form action =" mailto:my ***** @ mycompany.com" ID = QUOT; subinfo" method =" post"
name =" subinfo" enctype =" text / plain">
< input name =" Name"大小= QUOT; 24英寸; />< br />< br />



不使用< br />但< br>



他可能正在使用XHTML。


-

Ian Collins。


Hello Gurus:

I have a validation script (below) that is somehow messed up. If the
Name field is blank, I get the alert message, then the browser window
goes to a blank document with the word "false" on it. What the ?!?!?!

To test, I commented out the ''return false;'' code in the second IF
block, so now if there is a value in Name then I get the alert message
for Email and the page stays put.

What the heck is going on here, and am I doing wrong? BTW, the
"submit" button is a graphic.
<********** START CODE **********>
<script language="JavaScript" type="text/javascript">
<!--
function validate() {
var x = "0";

if (document.subinfo.Name.value == "") {
alert("You must enter your First Name.");
document.subinfo.Name.focus();
x.value = "1";
return(false); }

if (document.subinfo.Email.value == "" ||
document.subinfo.Email.value.indexOf("@") == -1 ||
document.subinfo.Email.value.indexOf(".") == -1) {
alert("Invalid email address. Please re-enter it.");
document.subinfo.Email.focus();
// return false; }
x.value = "1"; }

if (x.value == "0") {
launchwin(''thanks.html'',''confirmation'',''height=200 ,width=280'');
document.subinfo.submit();
location.href = "default.html"; }
}
-->
</script>

<form action="mailto:my*****@mycompany.com" id="subinfo" method="post"
name="subinfo" enctype="text/plain">
<input name="Name" size="24" /><br /><br />
<input name="Company" size="24" /><br /><br />
<input name="Email" size="24" /><br /><br />
<textarea name="Comments" cols="38" rows="5"></textarea><br /><br />
<a href="javascript:validate()">
<img src="gfx/send.gif" name="send" width="42" height="18"
alt="Send Form" />
</a>&nbsp;&nbsp;
<a href="javascript:document.inquiries.reset()">
<img src="gfx/clear.gif" name="clear" width="42" height="18"
alt="Clear Form" />
</a>
</form>

<********** END CODE **********>

Thanks,
Kurt

解决方案

wrote on 15 feb 2006 in comp.lang.javascript:

Hello Gurus:

I have a validation script (below) that is somehow messed up. If the
Name field is blank, I get the alert message, then the browser window
goes to a blank document with the word "false" on it. What the ?!?!?!

To test, I commented out the ''return false;'' code in the second IF
block, so now if there is a value in Name then I get the alert message
for Email and the page stays put.

What the heck is going on here, and am I doing wrong? BTW, the
"submit" button is a graphic.
<********** START CODE **********>
<script language="JavaScript" type="text/javascript">
do not use language="JavaScript"
<!--
do not use <!--
function validate() {
var x = "0";

if (document.subinfo.Name.value == "") {
alert("You must enter your First Name.");
document.subinfo.Name.focus();
x.value = "1";
return(false); }
should be:

return false; }

but then the x.value = "1"; would not be usefull,
so delete the return false here


if (document.subinfo.Email.value == "" ||
document.subinfo.Email.value.indexOf("@") == -1 ||
document.subinfo.Email.value.indexOf(".") == -1) {
alert("Invalid email address. Please re-enter it.");
document.subinfo.Email.focus();
// return false; }
well done //
x.value = "1"; }

if (x.value == "0") {
launchwin(''thanks.html'',''confirmation'',''height=200 ,width=280'');
what is launchwin() ???????????
document.subinfo.submit();
location.href = "default.html"; } }
-->
</script>

<form action="mailto:my*****@mycompany.com" id="subinfo" method="post"
name="subinfo" enctype="text/plain">
<input name="Name" size="24" /><br /><br />
do not use <br /> but <br>
<input name="Company" size="24" /><br /><br />
<input name="Email" size="24" /><br /><br />
<textarea name="Comments" cols="38" rows="5"></textarea><br /><br />
<a href="javascript:validate()">
<img src="gfx/send.gif" name="send" width="42" height="18"
alt="Send Form" />
</a>&nbsp;&nbsp;
href="javascript: is a bad idea, better do:

<form onsubmit=''validate()'' ...

and

<input src="gfx/send.gif" type=''image'' alt="Send Form">

<a href="javascript:document.inquiries.reset()">
<img src="gfx/clear.gif" name="clear" width="42" height="18"
alt="Clear Form" />
</a>
same here:

<img onclick=''document.inquiries.reset()'' src="gfx/clear.gif"
style=''cursor:pointer;''>
</form>

<********** END CODE **********>

Thanks,
Kurt



--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


Hello

1. Better make use of ONSUBMIT event

2. If you are just to fix what you wrote, simply add: void(0) after your
validate function call, just like in:

<script>
function fnc1()
{
if (/*validation ok*/)
{
// submit the form
FORM_VAR.submit();
return true;
}
return false;
}
</script>
</head>

<body>
<a href="javascript: fnc1();void(0);">adsasd</a>
</body>
</html>

HTH
Elias

<ku***@ev1.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

Hello Gurus:

I have a validation script (below) that is somehow messed up. If the
Name field is blank, I get the alert message, then the browser window
goes to a blank document with the word "false" on it. What the ?!?!?!

To test, I commented out the ''return false;'' code in the second IF
block, so now if there is a value in Name then I get the alert message
for Email and the page stays put.

What the heck is going on here, and am I doing wrong? BTW, the
"submit" button is a graphic.
<********** START CODE **********>
<script language="JavaScript" type="text/javascript">
<!--
function validate() {
var x = "0";

if (document.subinfo.Name.value == "") {
alert("You must enter your First Name.");
document.subinfo.Name.focus();
x.value = "1";
return(false); }

if (document.subinfo.Email.value == "" ||
document.subinfo.Email.value.indexOf("@") == -1 ||
document.subinfo.Email.value.indexOf(".") == -1) {
alert("Invalid email address. Please re-enter it.");
document.subinfo.Email.focus();
// return false; }
x.value = "1"; }

if (x.value == "0") {
launchwin(''thanks.html'',''confirmation'',''height=200 ,width=280'');
document.subinfo.submit();
location.href = "default.html"; }
}
-->
</script>

<form action="mailto:my*****@mycompany.com" id="subinfo" method="post"
name="subinfo" enctype="text/plain">
<input name="Name" size="24" /><br /><br />
<input name="Company" size="24" /><br /><br />
<input name="Email" size="24" /><br /><br />
<textarea name="Comments" cols="38" rows="5"></textarea><br /><br />
<a href="javascript:validate()">
<img src="gfx/send.gif" name="send" width="42" height="18"
alt="Send Form" />
</a>&nbsp;&nbsp;
<a href="javascript:document.inquiries.reset()">
<img src="gfx/clear.gif" name="clear" width="42" height="18"
alt="Clear Form" />
</a>
</form>

<********** END CODE **********>

Thanks,
Kurt



Evertjan. wrote:

<form action="mailto:my*****@mycompany.com" id="subinfo" method="post"
name="subinfo" enctype="text/plain">
<input name="Name" size="24" /><br /><br />


do not use <br /> but <br>


He might be using XHTML.

--
Ian Collins.


这篇关于“return false”给出一个带有“false”字样的空白页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆