传递变量 - 没有答案?! [英] passing variable - no answer?!

查看:73
本文介绍了传递变量 - 没有答案?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我之前写过,如果我调用变量name,我可以将变量从第1页传递到第2页




Stephen Chalmers写过,

''name''实际上是一个保留字,因为变量window.name是
自动创建,但不是只读的。
为变量使用更具想象力的名称。




这是否解释了为什么我可以从一个页面传递变量

另一个?


其他方法似乎要简单得多,例如用URL等传递

值。


这样做会产生任何负面影响吗?

干杯


Geoff

解决方案

Geoff Coxaécrit:

这是否解释了为什么我可以将变量从一个页面传递给<另一个?


没有什么比试一试更好:


档''page1.htm'':


< html> < title>第1页< / title>

< h3>第1页< / h3>

< form action =" page2.htm" onsubmit =" window.name = this.Name.value">

输入您的姓名:< input type = text name =" Name">

< input type = submit value = GO>

< / form>< / html>


file''page2.htm'':


< html> < title>第2页< / title>

< body onload =" document.forms [0] [0] .value = window.name;">

< h3>第2页< / h3>

< form>

您的姓名是:< input type = text name =" Name"> ;

< / form>< / body>< / html>

其他方法似乎要简单得多,例如通过
使用URL等的值。


是的,如果你只有一个值可以通过

这样做会产生任何负面影响吗?




有什么负面影响?

-

Stephane Moriaux et son [moins] vieux Mac


2005年9月29日星期四11:36:41 + 0200,ASM

< st **************** *****@wanadoo.fr.invalid>写道:

Geoff Coxaécrit:

这是否解释了为什么我可以将变量从一个页面传递给另一个页面?



没有什么比try-demo更好:

文件''page1.htm'':

< html> < title>第1页< / title>
< h3>第1页< / h3>
< form action =" page2.htm" onsubmit =" window.name = this.Name.value">
输入您的姓名:< input type = text name =" Name">
< input type = submit value = GO>
< / form>< / html>

文件''page2.htm'':

< html> < title>第2页< / title>
< body onload =" document.forms [0] [0] .value = window.name;">
< h3> page 2< / h3>
< form>
您的姓名是:< input type = text name =" Name">
< / form>< / body>< ; / html>

其他方法似乎要简单得多,例如用URL等传递
值。


这样做有没有任何负面影响?



有什么负面影响?




Stephane。


感谢您尝试这种方法。我没有看到任何提及这个

befofe。


我想知道这是否使用某种保留字。是否

这会导致任何问题吗?


干杯


Geoff





Geoff Coxaécrit:

2005年9月29日星期四11:36:41 + 0200,ASM
< st ********************* @ wanadoo.fr.invalid>写道:

Stephane。

感谢您尝试这种方法。我没有看到任何提及这个
befofe。

我想知道这是否使用一种保留字。是否这会导致任何问题吗?




如其他说的那样


''name''是一个javascript中所有内容的保留字


在这个try-demo中,这个保留字用于它所做的事情

那就是说:给对象的名称


因为''window''是javascript中的所有第一个对象



因为''窗口''可以省略


如果你的窗口有一个名字,你就是警告(名字)

,这将需要打开一个警告框窗口的名称


所以,这个try-demo可以变成:


file''page1.htm'':


< html> < title>第1页< / title>

< script type =" text / javascript">

function go(aName){name = aName; }

< / script>

< h3>第1页< / h3>

< form action =" page2.htm" ;>

输入您的姓名:

< input type = text name =" Name" onchange =" go(this.value);">

< input type = submit value = GO>

< / form>< / html> ;


档''page2.htm'':


< html>

< title>第2页< / title>

< body onload =" document.forms [0] .Name.value = name;">

< h3>第2页< / h3>

< form>

您的姓名是:

< input type = text name =" Name" >

< / body>< / form>< / html>

正如您现在所见,使用IE(不再使用FF工作) ),

你的变量''name'是什么?

实际上是保留字''name''

,因为使用过独自一人,是:窗口名称


这种特殊主义(一个窗口记录它的名字)

对弹出窗口很有用


-

Stephane Moriaux et son [moins] vieux Mac


Hello,

I have written before that I can pass a variable from page 1 to page 2
if I call the variable "name".

Stephen Chalmers has written,

''name'' is effectively a reserved word as the variable window.name is
created automatically, but is not read-only.
Use more imaginative names for variables.



Does this explain why I can pass the variable from one page to
another?

It does seem to be much simpler that other methods, eg passing the
value with the URL etc.

Does doing this have any negative side effect?
Cheers

Geoff

解决方案

Geoff Cox a écrit :

Does this explain why I can pass the variable from one page to
another?
nothing best than a try-demo :

file ''page1.htm'' :

<html> <title>page 1</title>
<h3>page 1</h3>
<form action="page2.htm" onsubmit="window.name=this.Name.value">
Enter your name : <input type=text name="Name">
<input type=submit value=GO>
</form></html>

file ''page2.htm'' :

<html> <title>page 2</title>
<body onload="document.forms[0][0].value = window.name;">
<h3>page 2</h3>
<form>
Your name is : <input type=text name="Name">
</form></body></html>
It does seem to be much simpler that other methods, eg passing the
value with the URL etc.
yes, if you have only one alone value to pass
Does doing this have any negative side effect?



what negative effect ?
--
Stephane Moriaux et son [moins] vieux Mac


On Thu, 29 Sep 2005 11:36:41 +0200, ASM
<st*********************@wanadoo.fr.invalid> wrote:

Geoff Cox a écrit :

Does this explain why I can pass the variable from one page to
another?



nothing best than a try-demo :

file ''page1.htm'' :

<html> <title>page 1</title>
<h3>page 1</h3>
<form action="page2.htm" onsubmit="window.name=this.Name.value">
Enter your name : <input type=text name="Name">
<input type=submit value=GO>
</form></html>

file ''page2.htm'' :

<html> <title>page 2</title>
<body onload="document.forms[0][0].value = window.name;">
<h3>page 2</h3>
<form>
Your name is : <input type=text name="Name">
</form></body></html>

It does seem to be much simpler that other methods, eg passing the
value with the URL etc.



yes, if you have only one alone value to pass

Does doing this have any negative side effect?



what negative effect ?



Stephane.

Thanks for trying this approach. I haven''t seen any mention of this
befofe.

I was wondering whether if this uses "a sort of reserved word" whether
this can cause any problems?

Cheers

Geoff





Geoff Cox a écrit :

On Thu, 29 Sep 2005 11:36:41 +0200, ASM
<st*********************@wanadoo.fr.invalid> wrote:

Stephane.

Thanks for trying this approach. I haven''t seen any mention of this
befofe.

I was wondering whether if this uses "a sort of reserved word" whether
this can cause any problems?



as said by otherwise

''name'' is a reserved word for everything in javascript

in this try-demo this reserved word is used for what it was done
that''s to say : to give a name to an object

because ''window'' is the all first object in javascript
and
because ''window'' can be omitted

if your window has a name and you do i.e. alert(name)
that would have to open an alert-box with the name of the window

so, this try-demo can become :

file ''page1.htm'' :

<html> <title>page 1</title>
<script type="text/javascript">
function go(aName) { name=aName; }
</script>
<h3>page 1</h3>
<form action="page2.htm">
Enter your name :
<input type=text name="Name" onchange="go(this.value);">
<input type=submit value=GO>
</form></html>

file ''page2.htm'' :

<html>
<title>page 2</title>
<body onload="document.forms[0].Name.value = name;">
<h3>page 2</h3>
<form>
Your name is :
<input type=text name="Name">
</body></form></html>
As you can see now, using IE (don''t more work with FF),
what was your variable ''name''
was in fact the reserved word ''name''
and, because used alone, was : name of window

This particularism (a window records its name)
is useful with popups

--
Stephane Moriaux et son [moins] vieux Mac


这篇关于传递变量 - 没有答案?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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