码迷,mamicode.com
首页 > Web开发 > 详细

js prompt

时间:2017-08-06 14:12:01      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:style   法则   border   document   警告   面积   判断   http   alert   

<title>综合练习3-2</title>
<script language="javascript">
<!--
    var r = prompt( "请输入圆的半径:", "0" );            // 用户输入圆半径
    if( r != null )                            // 判断输入的合法性
    {
        var square = parseFloat( r )*parseFloat( r )*Math.PI;    // 计面积 s=π*r*r
        document.write("半径为" + parseFloat( r ) + "的圆面积为:" + square );    // 在页面中输出结果
    }
    else                                // 输入不合法则给出警告
    {
        alert("输入不合法!");
    }    
-->
</script>

定义和用法

prompt()方法用于显示一个带有提示信息,并且用户可以输入的对话框。

语法

1
prompt(text,defaultText);

 

参数 描述
text 可选。要在对话框中显示的提示信息(纯文本)
defaultText 可选。默认的输入文本。

 

输出:

技术分享

 

js prompt

标签:style   法则   border   document   警告   面积   判断   http   alert   

原文地址:http://www.cnblogs.com/huodaihao/p/7294371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!