您的位置:首页 > Web前端 > JavaScript

JS中confirm,alert,prompt函数

2009-03-25 19:58 357 查看
 window.alert:参数,只有一个,显示警告框的信息;   
   无返回值.   
    
   <script>   
   window.alert("确定.")   
   </script>  

window.confirm :   参数就只有一个.显示提示框的信息.   
   按确定,返回true;    按取消返回false.   
    
   <script>   
   var    bln    =    window.confirm("确定吗?");   
   alert(bln)   
   </script>   

   window.prompt:参数,有两个,   
   第一个参数,显示提示输入框的信息.   
   第二个参数,用于显示输入框的默认值.   
   返回,用户输入的值.   
    
   <script>   
   var    str    =    window.prompt("请输入密码","password")   
   alert(str);   
   </script>

 

今天上午有一个面题目,是JS写函数。根据填写的年龄,判断是否正确,如果正确就页面就指向WebForm1.aspx,如果不正确就把指针停留在ttt上。

 

 年龄:<input name="ttt" type="text" value="5" />
    <button id="button1" onclick ="javascript:onsureForm()"></button>
    </div>
    </form>
    <script type="text/javascript" >
   function  onsureForm(){
    var age = document.getElementsByName("ttt")[0].value;
    if(confirm("area you sure your age is " + age )){
        window.location="WebForm1.aspx";
    }else{
        document.getElementsByName("ttt")[0].focus();
    }
   
   }
    </script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息