JavaScript一些函数

时间:2015-06-06 20:42:16   收藏:0   阅读:256

1.prompt()函数:有两个参数,一个是显示用户输入框上面的标签,另一个是输入框的初始值。用来接收用户输入的值,然后把它返回到代码中;

例如:

技术分享
 1 <doctype html>
 2 <html>
 3     <head>
 4         <title>Tset</title>
 5     </head>
 6     <body>
 7         <script type="text/javascript">
 8         var docElement =prompt("please enter your name","text");
 9            alert(docElement);
10         </script>
11     </body>
12 </html>
Prompt函数

谷歌浏览器中运行的效果图:

技术分享

2.Prompt函数返回的是字符串类型:

技术分享
 1 <doctype html>
 2 <html>
 3     <head>
 4         <title>Tset</title>
 5     </head>
 6     <body>
 7         <script type="text/javascript">
 8            var sum=1+2;
 9            document.write("the total num is:",sum);
10         </script>
11     </body>
12 </html>
1+2

效果图:

技术分享

使用Promrpt函数做上面的操作:

技术分享
 1 <doctype html>
 2 <html>
 3     <meta charset="utf-8"/>
 4     <head>
 5         <title>Tset</title>
 6     </head>
 7     <body>
 8         <script type="text/javascript">
 9            var num1=prompt("请输入一个数字")
10            var sum=1+num1;
11            document.write("the total num is:",sum);
12         </script>
13     </body>
14 </html>
prompt函数计算,返回值为字符串类型

效果图:

技术分享

技术分享

 

原文:http://www.cnblogs.com/caofangsheng/p/4557223.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!