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>
  • 相关阅读:
    32、至少列举8个常用模块都有那些?
    31、如何安装第三方模块?以及用过哪些第三方模块?
    uva120 Stacks of Flapjacks (构造法)
    stringstream的基本用法
    Codeforces Round #246 (Div. 2) C. Prime Swaps(贪心,数论)
    Codeforces Round #271 (Div. 2)D(递推,前缀和)
    poj3061 Subsequence&&poj3320 Jessica's Reading Problem(尺取法)
    Codeforces Round #266 (Div. 2)B(暴力枚举)
    uva10815(set的应用)
    uva489(需要考虑周全)
  • 原文地址:https://www.cnblogs.com/greatverve/p/1554307.html
Copyright © 2011-2022 走看看