为什么这不起作用? [英] Why doesn't this work?

查看:63
本文介绍了为什么这不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我这段代码有什么问题吗?


< script language =" JavaScript">

function myFunction2( ){

document.write(''Link< a href =" javascript :myFunction1()"> A< / a>'')}


函数myFunction1(){

document.write(''Link< a href =" javascript :myFunction2() "> B< / a>'')}

< / script>


< body>

开始于

< a href =" javascript :myFunction2()"> here< / a>

< / body> ;


我点击这里我看到链接A的页面。

我点击A和A。并且,而不是按预期看到带有链接B的页面,

我得到页面错误。


感谢任何想法。

解决方案

您好,


您必须拥有<脚本语言...... ;在document.write()参数中。


在你的第一个clic之后查看你的源代码,你就会理解你的

错误。


M

有人能告诉我这段代码有什么问题吗?

< script language =" JavaScript">
函数myFunction2(){
document.write(''Link< a href =" javascript :myFunction1()"> A< / a>'')}

函数myFunction1(){
document.write(''Link< a href =" javascript :myFunction2()" ;> B< / a>'')}
< / script>

< body>

< a href ="开头javascript :myFunction2()"> here< / a>
< / body>

我点击here"我看到链接A的页面。
我点击A。并且,而不是按预期看到带有链接B的页面,
我得到页面错误。

感谢您的任何想法。



ci****@oduibhin.freeserve.co.uk 写道:

有人能告诉我这段代码有什么问题吗?

< script language =" JavaScript">


要成为有效的HTML,它应该使用type属性:

< script type =" text / javascript">

但这不是你问题的根源。

函数myFunction2(){
document.write(''Link< a href =" javascript :myFunction1()"> A< / a>'')}

函数myFunction1(){
document.write(''Link< a href = " javascript :myFunction2()"> B< / a>'')}
< / script>

< body>
开始于
< a href =" javascript :myFunction2()"> here< / a>
< / body>

我点击这里我看到链接A的页面。


当您单击here时,您在

已完成加载的文档上执行document.write。这会清除页面并开始一个新的页面

并写入。

我点击A并且,而不是按预期看到带有链接B的页面,
我得到页面错误。




在新页面上,没有定义名为

" myFunction1"的函数的脚本。

/ L

-

Lasse Reichstein Nielsen - lr*@hotpop.com

DHTML死亡颜色:< URL:http://www.infimum.dk /HTML/rasterTriangleDOM.html>

''没有判断的信仰只会降低精神神圣。''


写于04 mei 2006 in comp .lang.javascript

有人能告诉我这段代码有什么问题吗?

< script language = JavaScript>
函数myFunction2(){
document.write(''Link< a href =" javascript :myFunction1()"> A< ; / a>'')}

函数myFunction1(){
document.write(''Link< a href =" javascript :myFunction2()"> B< / a>'')}
< / script>

< body>
开始在
< a href =" javascript :myFunction2()"> here< / a>
< / body>

我点击这里我看到链接A的页面。


不,你不是。


你看到a页面,但不是的页面,

因为html被完全覆盖了,甚至脚本都没了。

我点击A并且,而不是按预期看到带有链接B的页面,
我得到页面错误。




不再有stript了。 />

================

页面完成后
document.write(),

发出一个隐含的document.open()并清除页面源。

-

Evertjan。

荷兰。

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


Can anyone tell me what it wrong with this code, please?

<script language="JavaScript">
function myFunction2(){
document.write (''Link <a href="javascript:myFunction1()">A</a>'')}

function myFunction1(){
document.write (''Link <a href="javascript:myFunction2()">B</a>'')}
</script>

<body>
Start in
<a href="javascript:myFunction2()">here</a>
</body>

I click on "here" and I see the page with link "A".
I click on "A" and, instead of seeing the page with link B as expected,
I get "Error in page".

Thanks for any ideas.

解决方案

Hello,

You have to had "<script language..." in the document.write() parameter.

Look at your source code after your first clic, you''ll understand your
mistake.

M

Can anyone tell me what it wrong with this code, please?

<script language="JavaScript">
function myFunction2(){
document.write (''Link <a href="javascript:myFunction1()">A</a>'')}

function myFunction1(){
document.write (''Link <a href="javascript:myFunction2()">B</a>'')}
</script>

<body>
Start in
<a href="javascript:myFunction2()">here</a>
</body>

I click on "here" and I see the page with link "A".
I click on "A" and, instead of seeing the page with link B as expected,
I get "Error in page".

Thanks for any ideas.



ci****@oduibhin.freeserve.co.uk writes:

Can anyone tell me what it wrong with this code, please?

<script language="JavaScript">
To be valid HTML, it should use the type attribute:
<script type="text/javascript">
It''s not the source of your problems though.
function myFunction2(){
document.write (''Link <a href="javascript:myFunction1()">A</a>'')}

function myFunction1(){
document.write (''Link <a href="javascript:myFunction2()">B</a>'')}
</script>

<body>
Start in
<a href="javascript:myFunction2()">here</a>
</body>

I click on "here" and I see the page with link "A".
When you click "here", you do a document.write on a document that
has finished loading. That clears the page and starts a new one
and writes into that.
I click on "A" and, instead of seeing the page with link B as expected,
I get "Error in page".



On the new page, there is no script defining a function called
"myFunction1".
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
''Faith without judgement merely degrades the spirit divine.''


wrote on 04 mei 2006 in comp.lang.javascript:

Can anyone tell me what it wrong with this code, please?

<script language="JavaScript">
function myFunction2(){
document.write (''Link <a href="javascript:myFunction1()">A</a>'')}

function myFunction1(){
document.write (''Link <a href="javascript:myFunction2()">B</a>'')}
</script>

<body>
Start in
<a href="javascript:myFunction2()">here</a>
</body>

I click on "here" and I see the page with link "A".
No, you don''t.

You see "a" page, but not "the" page,
since the html is completely overwritten, and even the script is gone.
I click on "A" and, instead of seeing the page with link B as expected,
I get "Error in page".



There is no stript anymore.

================

document.write() after the page is finished,
issues an implicit document.open() and clears the page source.
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


这篇关于为什么这不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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