简单的错误? [英] simple error?

查看:35
本文介绍了简单的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我试图再次打印出数组值但在页面消息上出现

错误?


谢谢


Geoff


< html>

< HEAD>


< SCRIPT language =" JavaScript">

<! -

function display_questions()

{

var questions = new Array(5)

questions [0] ="问题1" ;;

问题[1] ="问题2;

问题[2] ="问题3" ;;

问题[3] ="问题4" ;;

questions [4] =" question 5";

var x = 0;

for(x = 0; x< 5; x ++)

{

document.write(questions [x] +"< br>");

}

document.write("< input type =''button''value =''again''onclick =''again()''/

Hello,

I am trying to print out the array values for a second time but get
error on page message?

Thanks

Geoff

<html>
<HEAD>

<SCRIPT language="JavaScript">
<!--
function display_questions()
{
var questions= new Array(5)
questions[0]="question 1";
questions[1]="question 2";
questions[2]="question 3";
questions[3]="question 4";
questions[4]="question 5";
var x=0;
for (x=0; x<5; x++)
{
document.write(questions[x] + "<br>");
}
document.write("<input type=''button'' value=''again'' onclick=''again()'' /

");




}

再次起作用()

{

var i = 0;

for(i = 0;我小于5; i ++)

{

document.write(this.questions [i] +"< br>");

} < br $>

}

< / SCRIPT>


< / HEAD>

< BODY>


< input type =" button" value ="查看问题"

onclick =" display_questions()" />

< / BODY>

< / html>



}

function again()
{
var i=0;
for (i = 0; i<5; i++)
{
document.write(this.questions[i] + "<br>");
}

}
</SCRIPT>

</HEAD>
<BODY>

<input type="button" value="see questions"
onclick="display_questions()" />
</BODY>
</html>

推荐答案

你好Geoff,

问题是当你做document.write时你实际上已经清除了

函数再次本身。这就是为什么它再次抱怨

未定义。

解决方案:

1.再次写使用document.write()再次运行。

[OR]

2.不要使用document.write,而是在div中动态写入或者

" span" ;.


- Peroli Sivaprakasam


Geoff Cox写道:
Hi Geoff,
The problem is when you did "document.write" you actually cleared
the function "again" itself. Thats why it complains "again is
notdefined".
Solutions:
1. Write "again" function again using document.write().
[OR]
2. Dont use document.write, instead write dynamically in a "div" or
"span".

- Peroli Sivaprakasam

Geoff Cox wrote:
你好,

我试图第二次打印出数组值但在页面消息上出现
错误?

谢谢

Geoff
< html>
< HEAD>

< SCRIPT language =" JavaScript">
< ! -
功能display_questions()
{
var questions = new Array(5)
问题[0] ="问题1" ;;
问题[1 ] =问题2;
问题[2] ="问题3" ;;
问题[3] ="问题4" ;;
问题[4] ="问题5;
var x = 0;
for(x = 0; x <5; x ++)
{
document.write(questions [x] +"< br>");
}
document.write("< input type =''button''value =''again''onclick =''again()''/
Hello,

I am trying to print out the array values for a second time but get
error on page message?

Thanks

Geoff

<html>
<HEAD>

<SCRIPT language="JavaScript">
<!--
function display_questions()
{
var questions= new Array(5)
questions[0]="question 1";
questions[1]="question 2";
questions[2]="question 3";
questions[3]="question 4";
questions[4]="question 5";
var x=0;
for (x=0; x<5; x++)
{
document.write(questions[x] + "<br>");
}
document.write("<input type=''button'' value=''again'' onclick=''again()'' /
");


}

再次起作用()
{var /> var i = 0;
for(i = 0;我小于5; i ++)
{
document.write(this.questions [i] +"< br>");
}

}
< / SCRIPT>

< / HEAD>
< BODY>

< input type =" button" value =" see questions"
onclick =" display_questions()" />

< / BODY>
< / html>



}

function again()
{
var i=0;
for (i = 0; i<5; i++)
{
document.write(this.questions[i] + "<br>");
}

}
</SCRIPT>

</HEAD>
<BODY>

<input type="button" value="see questions"
onclick="display_questions()" />
</BODY>
</html>






On 2 2005年9月01:57:24 -0700,Peroli < PE **** @ gmail.com>写道:
On 2 Sep 2005 01:57:24 -0700, "Peroli" <pe****@gmail.com> wrote:
嗨Geoff,
问题是当你做document.write时你实际上已经清除了再次功能本身。这就是为什么它抱怨再次是
未定义。
解决方案:
1。再写再次使用document.write()再次运行。
[OR]
2。不要使用document.write,而是在div中动态写入。或者
span。
Hi Geoff,
The problem is when you did "document.write" you actually cleared
the function "again" itself. Thats why it complains "again is
notdefined".
Solutions:
1. Write "again" function again using document.write().
[OR]
2. Dont use document.write, instead write dynamically in a "div" or
"span".




Peroli,


你能告诉我你的意思吗?通过第二个选项?!


干杯


Geoff



Peroli,

Could you please give me an idea what you mean by the second option?!

Cheers

Geoff


Geoff Cox< ge ******* @ notquitecorrectfreeuk.com>写道:
Geoff Cox <ge*******@notquitecorrectfreeuk.com> writes:
我试图再次打印出数组值但是在页面消息上出现
错误?


你得到什么错误信息? (如果您使用IE,则在开发时应启用

错误消息)。

< SCRIPT language =" JavaScript">


应该是< script type =" text / javascript">

<! -


没必要。

功能display_questions()
{
var questions = new Array(5)


这里有问题 ;在

" display_questions"中声明为局部变量功能。 问题变量只是在这个函数中可见


document.write("< input type =''button''value =''again''onclick =' 'again()''/
I am trying to print out the array values for a second time but get
error on page message?
What error message do you get? (If you use IE, you should enable
error messages when doing development).
<SCRIPT language="JavaScript">
Should be <script type="text/javascript">
<!--
Not necessary.
function display_questions()
{
var questions= new Array(5)
Here "questions" is declared as a local variable inside the
"display_questions" function. The "questions" variable is only
visible inside this function.
document.write("<input type=''button'' value=''again'' onclick=''again()'' /
");



您似乎正在尝试document.write一个XHTML元素(结束

" />"看起来像XHTML),但是document.write通常不会为解析的XHTML页面工作




无论如何,当单击此按钮时,再次调用函数。

函数再次()
{var /> var i = 0;
for(i = 0; i< 5; i ++)


更短一点:

for(var i = 0; i< 5; i ++)

{
document.write(this.questions [i] +"< br>");


通过用户点击按钮调用。这表明

页面在调用时已经完成加载。在完成加载后在页面上执行document.write

将删除整个页面,并且

将其替换为所写的内容。


另外,this operator是指全局对象(又名window),

,它没有问题。属性。

< input type =" button" value =" see questions"
onclick =" display_questions()" />


You seem to be trying to document.write an XHTML element (the closing
"/>" looks like XHTML), but document.write generally doesn''t work
for XHTML pages parsed as such.

Anyway, when this button is clicked, the again function is called.
function again()
{
var i=0;
for (i = 0; i<5; i++)
A little shorter:
for (var i = 0; i < 5; i++)
{
document.write(this.questions[i] + "<br>");
This is called through a user click on a button. That suggests that the
page is already done loading when this is called. Doing "document.write"
on a page after it has finished loading will erase the entire page, and
replace it with what is written.

Also, the "this" operator refers to the global object (aka "window"),
which doesn''t have a "questions" property.
<input type="button" value="see questions"
onclick="display_questions()" />




这会调用第一个函数,它也会删除页面。


通常,document.write是不是向页面添加内容的方式

已经加载。有不同的方法可以做到这一点,通过W3C DOM或使用专有的innerHTML来实现
。物业。

< URL:http://jibbering.com/faq/#FAQ4_15>


/ L

- -

Lasse Reichstein Nielsen - lr*@hotpop.com

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

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



And this calls the first function, which also erases the page.

Generally, document.write is not the way to add content to a page
that is already loaded. There are different ways to do that, either
through the W3C DOM or using the proprietary "innerHTML" property.
<URL:http://jibbering.com/faq/#FAQ4_15>

/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.''


这篇关于简单的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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