• 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>
  • 相关阅读:
    jQuery proxy详解
    LESSCSS
    JavaScript语法支持严格模式:"use strict"
    C++ 使用cl命令编辑时发生的问题收录
    attachEvent和addEventListener
    Alert方法重写
    广播信道的数据链路层
    js prototype之诡异
    前端开发易忘内容收录
    数据链路层-点对点协议PPP
  • 原文地址:https://www.cnblogs.com/greatverve/p/1554307.html
Copyright © 2020-2023  润新知