Javascript基础

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Button1" type="button" value="确认框" onclick="change()" />
        <input id="Button2" type="button" value="提示框"  onclick="tishi()"/>
        <input id="Button3" type="button" value="dowhile"  onclick="dowhile()"/>
        <input id="Button4" type="button" value="检测"  onclick="jiance()"/>
        <input id="Button5" type="button" value="计时"  onclick="timedCount()"/>

        <input id="txt" type="text"  />
    </div>
    </form>
</body>
</html>
<script>
    function change()  //确认框
    {
        var r = confirm("是否保存");
        if (r == true) {
            alert("您点击的是确定");
        }
        else {
            alert("您点击的是取消");
        }
    }

    function tishi()  //提示框
    {
        var name = prompt("请输入您的姓名", "刘凯");
        if(name!="")
        {
            document.write("您好",name);
        }
    }
    function dowhile() //dowhile 循环输出数字
    {
        i = 1;
        do
        {
            document.write("数字是" + i);
            document.write("<br/>");
            i++;
        }
        while(i<=5)
    }
  
    function jiance()
    {
        var browser = navigator.appName //浏览器名称
        var b_version = navigator.appVersion
        //document.write(b_version)
        //document.write("<br/>")
        var version = parseFloat(b_version)  //浏览器版本 parseFloat() 全局函数,解析字符串
        document.write("浏览器名称:" + browser)
        document.write("<br />")
        document.write("浏览器版本:" + version)
        document.write("<p>代码:")
        document.write(navigator.appCodeName + "</p>")

        document.write("<p>平台:")
        document.write(navigator.platform + "</p>")

        document.write("<p>Cookies 启用:")
        document.write(navigator.cookieEnabled + "</p>")

        document.write("<p>浏览器的用户代理报头:")
        document.write(navigator.userAgent + "</p>")
    }

    //循环计时
    var c = 0
    function timedCount()
    {
        document.getElementById("txt").value = c
        c = c + 1
       window.setTimeout("timedCount()", 1000)
    }
      
</script>

 

posted @ 2015-08-17 17:38  XCml  阅读(199)  评论(0编辑  收藏  举报