zoukankan      html  css  js  c++  java
  • javascript数组练习

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        
    <title>javascript数组学习</title>
        
    <script type="text/javascript">
            
    function debug(o){a=[];for(k in o)a.push(k+":"+o[k]);alert(a.join("\n"))}
            
    //javascript数组学习
            function f1(){
                a
    =[];//定义一个数组
                a.push("1");//通过push方法向数组中添加数据,追加
                a.push("2");
                a[
    2]="001";//通过下标添加
                //alert(a);//默认数组是用","分隔开
                //alert(a.join("\n"));//join的作用是把分隔符替换成"\n"
                //alert(a.join("|"));
                for(k in a){//遍历数组,这里的k会从0到a的长度
                    alert(a[k]+"|"+k);
                }
                
    //document.domain="0379zd.com";//只读的
                alert(document.domain);
                
    //url编码解码
                var s = encodeURIComponent("http://www.0379zd.com");//编码
                alert(decodeURIComponent(s));//解码
            }
            
    function getform(f){
                
    if(!f) f=document.forms[0];
                
    var s='';
                
    for(var i=0;i<f.length;i++){
                    
    var e=f[i];
                    
    if(e.id)
                        s
    +='&'+e.id+'='+encodeURIComponent(e.value)
                }
                
    //return s
                alert(s);
            }
        
    </script>
    </head>
    <body>
    <form id="form1" action="" onclick="getform(this);">form</form>
    <input type="button" onclick="f1();" value="ok" />
    <input type="button" onclick="debug(this);" value="debug" />
    <div onclick="debug(this);">click</div>
    <div>form</div>
    </body>
    </html>
  • 相关阅读:
    C语言函数运行时间测试
    C++无需创建实例而访问类成员函数
    Why do I get "Value computed is not used" when working with pointers?
    指针数组以及指向字符串的理解
    彻底了解指针数组,数组指针,以及函数指针,以及堆中的分配规则
    结构体(struct) 的 sizeof 大小
    C语言深入学习系列 字节对齐&内存管理
    C语言字节对齐详解
    poj2945
    poj2110
  • 原文地址:https://www.cnblogs.com/greatverve/p/1554307.html
Copyright © 2011-2022 走看看