Javascript阵列警报

编程入门 行业动态 更新时间:2024-10-11 09:27:11
本文介绍了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 。

jsfiddle/5b2eb/

但是,如果你想干净地显示它们,你的弹出窗口中每行一个,就这样做:

However, if you want to display them cleanly, one per line, in your popup, do this:

alert(aCustomers.join("\n"));

http: //jsfiddle/5b2eb/1/

更多推荐

Javascript阵列警报

本文发布于:2023-11-27 21:47:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639713.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阵列   警报   Javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!