zoukankan      html  css  js  c++  java
  • Prompt isNaN 数组 function DOM window.open/close/location/history

    1、prompt的利用

    <%@ 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>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <asp:Button ID="Button1" runat="server" Text="Button" />
    
        </div>
        </form>
    </body>
    </html>
    <script>
        document.getElementById("Button1").onclick = function ()//Button1的点击事件
        {
            var a = prompt("请输入内容");//接受prompt的值的内容赋值给a
            document.getElementById("Label1").innerHTML = a;//把a赋值给label1
            return false;//阻止页面刷新。如果没有这个,页面就会回到刚开始页面加载的样子
        }
    
    </script>
    View Code

    2、JS中数字和文本的结合的输出结果

    <script>
        document.getElementById("Button1").onclick = function ()//Button1的点击事件
        {
            var a = "10";
            var b = 20;
            var c = 30;
            alert(a + b + c);//返回102030
            alert(b + c + a);//5010
            alert(b + a + c);//201030
            alert(parseInt(a) + b);//输出30,注意parseInt()方法
            alert(b.toString()+a);//输出2010
            alert(b+""+c);//输出2030,注意中间的"".
    
        }
    View Code

     3、JS保证文本框内只有数字(isNaN())

    <%@ 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>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <asp:Button ID="Button1" runat="server" Text="Button" />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    
        </div>
        </form>
    </body>
    </html>
    <script>
        document.getElementById("TextBox1").onkeyup = function ()
        {
      
            if (isNaN(this.value))//“不是一个纯数字?”true表示“不是一个数字”,false表示是一个数字
            {
                this.value = this.value.substr(0,this.value.length-1);//文本框的值只保留数字部分
            }
        }
    
    </script>
    View Code

    4、JS下 for(i in "aaa") {alert(i);}

    <%@ 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>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <asp:Button ID="Button1" runat="server" Text="Button" />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    
        </div>
        </form>
    </body>
    </html>
    <script>
        document.getElementById("Button1").onclick = function ()
        {
            var a = "asdfg";
            for (i in a)
            {
                alert(i);//依次弹出a的所有索引号0,1,2,3,4
            }
           
        }
    
    </script>
    View Code

    5、JS 下数组的建立,添加和取值   var al = new Array(); 数组的数量用length

    <script>
        document.getElementById("Button1").onclick = function ()
        {
            var al = new Array();//建立JS的数组,相当于C#的集合,不限长度,不限数据类型
            al[0] = 1;//给数组添加数据
            al[1] = "2";//给数组添加数据
            var b = al[1];//取数组内的某一个值   
        }
    </script>
    View Code

    6、JS的函数function(){}

    <script>
        
        function aaa(a,b)//aaa为函数名称 a,b为根据需要添加的参数,不用在此限制ab的数据类型
        {
            alert("a"); //执行语句
            //根据具体情况看有没有需要rerurn,有就写上,没有就不用谢。
        }
        function bbbb()//没有参数的函数bbb
        {
        执行语句
        }
    </script>
    View Code

    7.DOM获取元素方式

    <script>
        
        var a = document.getElementById("Id值");//按照Id获取元素,获得一个元素
        var b = document.getElementsByClassName("Class值");//按照Class获取,获得一堆元素,返回一个集合
        var c = document.getElementsByTagName("元素名");//按照元素名称获取,获得一堆元素,返回一个集合
        //什么是元素名?比如div img span input,注意button不是
        var d = document.getElementsByName("name值");//按照name称获取,获得一堆元素,返回一个集合,name是给服务端用的
        //后两者在实际中不实用,后两者实现的效果,前两者都能实现,而且更准备
    </script>
    View Code

    8、window.open()的各项参数

    <script>
        window.open("page.html", "_blank", "height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")   //该句写成一行代码
        //参数解释:
        //window.open 弹出新窗口的命令; 
        //'page.html' 弹出窗口的文件名; 
        //'_blank' 弹出d到新的空的窗口
        //height=100 窗口高度; 
        //width=400 窗口宽度; 
        //top=0 窗口距离屏幕上方的象素值; 
        //left=0 窗口距离屏幕左侧的象素值; 
        //toolbar=no 是否显示工具栏,yes为显示; 
        //menubar,scrollbars 表示菜单栏和滚动栏。 
        //resizable=no 是否允许改变窗口大小,yes为允许; 
        //location=no 是否显示地址栏,yes为允许; 
        //status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
    </script>
    View Code

    9、window.history

    <script>
        window.history.back();//向后退一个界面
        window.history.forward();//向前进一个界面
        window.history.go(n);//n为int类型,-1表示向后退一个界面,1表示向前进一个界面
    </script>
    View Code

    10、window.location.href

    <script>
        var a = window.location.href;//获取当前页面的地址
        window.location.href("http://www.baidu.com");//只能在本页面重新打开百度页面,如果要单独打开新页面,必须用window.open();
    </script
    View Code

    完!!

  • 相关阅读:
    P2522 [HAOI2011]Problem b(容斥)
    P3455 [POI2007]ZAP-Queries
    P2519 [HAOI2011]problem a(线段树优化dp+思维)
    P2516 [HAOI2010]最长公共子序列 (lcs+容斥)
    [HAOI2010]软件安装(缩点+树形dp)
    P2508 [HAOI2008]圆上的整点(神仙题)
    [SDOI2011]消防(树的直径+二分||单调队列)
    QLabel设置字体颜色
    Qt绘制不规则串口
    C++继承关系
  • 原文地址:https://www.cnblogs.com/wwz-wwz/p/5990323.html
Copyright © 2011-2022 走看看