Javascript Array Alert(Javascript 数组警报)
问题描述
我是 Javascript 新手.
Im new to Javascript.
我正在尝试编写这四个按钮.我目前在做第二个.我编写了一个数组.但是当我点击按钮时,它会替换页面.我想在警告框中显示数组.
Im trying to code these four buttons. I'm currently on the second one. I've coded an array. But when I click on the button, it replaces the page. I want to display the array in an alert box.
<html>
<head>
<script type="text/javascript">
function SayHello()
{
alert("Hello World!");
}
function DumpCustomers()
{
var aCustomers=new Array();
aCustomers[0]="Frank Sinatra ";
aCustomers[1]="Bob Villa ";
aCustomers[2]="Kurt Cobain ";
aCustomers[3]="Tom Cruise ";
aCustomers[4]="Tim Robbins ";
aCustomers[5]="Santa Claus ";
aCustomers[6]="Easter Bunny ";
aCustomers[7]="Clark Kent ";
aCustomers[8]="Marry Poppins ";
aCustomers[9]="John Wayne ";
document.write(aCustomers[0]);
document.write(aCustomers[1]);
document.write(aCustomers[2]);
document.write(aCustomers[3]);
document.write(aCustomers[4]);
document.write(aCustomers[5]);
document.write(aCustomers[6]);
document.write(aCustomers[7]);
document.write(aCustomers[8]);
document.write(aCustomers[9]);
}
function DisplayFishCounts()
{
}
function FindJonGalt()
{
}
</script>
</head>
<body>
<form name="Main">
<input type="button" id=1 onclick="SayHello();" value="Say Hi"/>
<input type="button" id=1 onclick="DumpCustomers();" value="Dump Customers"/>
<input type="button" id=1 onclick="DisplayFishCounts();" value="Display Fish Counts"/>
<input type="button" id=1 onclick="FindJonGalt();" value="Where is Jon Galt?"/>
</form>
</body>
</html>
推荐答案
如果想把数组看成数组,可以说
If you want to see the array as an array, you can say
alert(JSON.stringify(aCustomers));
而不是所有那些 document.write
s.
http://jsfiddle.net/5b2eb/
但是,如果您想在弹出窗口中清晰地显示它们,每行一个,请执行以下操作:
However, if you want to display them cleanly, one per line, in your popup, do this:
alert(aCustomers.join("
"));
http://jsfiddle.net/5b2eb/1/
这篇关于Javascript 数组警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Javascript 数组警报


基础教程推荐
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01