提示不工作 [英] prompt not working

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

问题描述

我刚开始使用javascript而且以下内容无法正常工作

应该如此。预期的提示对话框永远不会出现。


< head>

< script language =" JavaScript"><! -

var name;

name = prompt(" Please please your name。","");

document.write(" ;我的名字是:",name);

// - >< / script>

< / head>

< body>

< p>它运作正常吗?

< / body>

< / html>


我试过用
$替换

< script language =" JavaScript">

b $ b< script type =" text / javascript">

但这对结果没有影响,如下:


我的名字是:


好​​吗?


我做错了什么?


Joe

I''m just starting out with javascript and the following is not working
as it should. The expected prompt dialog box never appears.

<head>
<script language="JavaScript"><!--
var name;
name=prompt("Please enter your name.","");
document.write("My name is: ", name);
// --></script>
</head>
<body>
<p>Did it work out ok?
</body>
</html>

I''ve tried replacing
<script language="JavaScript">
with
<script type="text/javascript">
but this makes no difference in the results, which are as follows:

My name is:

Did it work out ok?

What am I doing wrong?

Joe

推荐答案



joemac写道:

joemac wrote:
我''我刚开始使用javascript以及以下内容无法正常工作
。预期的提示对话框永远不会出现。

< head>
< script language =" JavaScript"><! -
var name;
name = prompt(请输入你的名字。,");
document.write("我的名字是:",名称);
// - > ;< / script>
< / head>
< body>
< p>它运作正常吗?
< / body>
< / html>

我试过用
< script type ="替换
< script language =" JavaScript">
text / javascript">
但这对结果没有影响,如下所示:

我的名字是:

好吗?

我做错了什么?
I''m just starting out with javascript and the following is not working
as it should. The expected prompt dialog box never appears.

<head>
<script language="JavaScript"><!--
var name;
name=prompt("Please enter your name.","");
document.write("My name is: ", name);
// --></script>
</head>
<body>
<p>Did it work out ok?
</body>
</html>

I''ve tried replacing
<script language="JavaScript">
with
<script type="text/javascript">
but this makes no difference in the results, which are as follows:

My name is:

Did it work out ok?

What am I doing wrong?




我不知道......它的工作方式如同发布,也许你没有输入名字?


很少有人建议:document.write()清除文件内容后,页面已经完成加载。
它几乎不是你想要的。

你可能想要使用DOM方法。在页面加载完毕之前,DOM方法并不是真正可用的(不是你的

函数)。因此,优先顺序为:


1)您首先加载页面

2)加载事件调用你的函数

3)你的函数完成了所有可以想象的(和不可想象的;-)的事情

你的页面


< ; html>

< head>

< title> Hello world!< / title>

< meta http-equiv = Content-Type

content =" text / html; charset = iso-8859-1">


< script type =" text / javascript">


// Global变量:

var myName ="" ;;


函数myFunction(){

//局部变量:

var sysOut = document.getElementById(" sysOut");


myName = prompt(" Please please your name:","") ;


if(myName){

sysOut.innerHTML ="你的名字是:" + myName;

}

else {

sysOut.innerHTML ="你没告诉我你的名字......: - (& ;;

}

}

< / script>


< / head>


< body onload =" myFunction()">


< div id =" sysOut">好吗?< / div>


< / body>


< / html>



I donno... It works as it posted, maybe your did not type the name in?

Few advises though: document.write() clears the document content after
the page has been finished to load. It is almost never what you want.
You may want to use DOM methods instead. And DOM methods are not
realibly available until the page finished to load (neither your
functions). Thus the preffered sequence would be:

1) You load the page first
2) The "load" event calls your function
3) Your function does all imaginable (and unimaginable ;-) things with
your page

<html>
<head>
<title>Hello world!</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<script type="text/javascript">

// Global variable:
var myName = "";

function myFunction() {
// Local variable:
var sysOut = document.getElementById("sysOut");

myName = prompt("Please enter your name:","");

if (myName) {
sysOut.innerHTML = "Your name is: " + myName;
}
else {
sysOut.innerHTML = "You did not tell me your name... :-(";
}
}
</script>

</head>

<body onload="myFunction()">

<div id="sysOut">Did it work out ok?</div>

</body>

</html>


>我不知道...它的工作方式如同发布,也许你没有输入名字?


正如我所说,对话框没有出现 - 所以我没有地方可以输入名字。
>I donno... It works as it posted, maybe your did not type the name in?

As I said, the dialog box does not appear - so there is no place for me
to type in the name.
很少有人建议:document.write()
页面加载后清除文档内容。几乎不是你想要的。
你可能想要使用DOM方法。
Few advises though: document.write() clears the document content after
the page has been finished to load. It is almost never what you want.
You may want to use DOM methods instead.




感谢您的提示,但此时我只是关注

指令我在书中给出的ns用来学习

语言。如果这不是最好的方法那么我肯定作者将会在稍后解释这个并给出新的例子。既然你说代码

为你工作,那么它必须是可行的。必须有一些与我的运行时环境不同的东西,导致它不能为我工作,这就是我需要深入了解的。


我尝试执行你提供的代码作为一个反例,

它同样对我不起作用。没有提示框

出现了,我得到了以下结果:


你没有告诉我你的名字...... :-(


Joe



Thanks for the tip but at this point I am simply following the
instructions as given in the book that I am using to learn the
language. If it is not the best approach then I''m sure the author will
explain that later on and give new examples. Since you said the code
worked for you as posted then it must be viable. There must be
something different about my runtime environment which causes it not to
work for me, and this is what I need to get to the bottom of.

I tried executing the code that you provided as a counter example and
it likewise did not work for me as it should have. No prompt box
appeared and I got the following result:

You did not tell me your name... :-(

Joe


joemac写道:
我尝试执行你提供的代码作为反例和
它同样对我不起作用。没有提示框
出现,我得到了以下结果:

你没有告诉我你的名字......: - (
I tried executing the code that you provided as a counter example and
it likewise did not work for me as it should have. No prompt box
appeared and I got the following result:

You did not tell me your name... :-(




这意味着那个


选项A)你的浏览器不支持JavaScript - 非常不可能

但是...


选项B)您提高了安全设置,因此您的浏览器禁用了JavaScript。




在后一种情况下(如果是Internet Explorer):

1)运行Internet Explorer

2)工具>互联网选项...>安全选项卡

3)选择互联网区域并单击自定义级别

4)找到活动脚本部分并将其设置为启用

您可以留下的其他设置是。


如果您不想要(或不是)允许)更改任何设置,然后你

必须转到 http:/ /www.mozilla.org ,获取最新版本的Firefox

浏览器并使用它来学习JavaScript。并使用Internet Explorer

浏览互联网。



It means then that

Option A) You browser doesn''t support JavaScript - highly unlikely
but...

Option B) You raised security settings too high so JavaScript became
disabled on your browser.

In the latter case (if Internet Explorer):
1) run Internet Explorer
2) Tools > Internet Options... > Security tab
3) Select "Internet" zone and click "Custom level"
4) Find the "Active scripting" section and set it to "Enable"
The rest of settings you may leave is they are.

If you don''t want (or not allowed) to change any settings, then you
have to go to http://www.mozilla.org, get the newest version of Firefox
browser and use it to learn JavaScript. And use Internet Explorer to
browse the Internet.


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

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