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>
  • 相关阅读:
    [转]vim 退格键(backspace)不能用
    centos出现“FirewallD is not running”怎么办
    cordova 实现拨打电话-只需两步(H5)
    腾讯云上运行java程序过程
    centos7 安装php
    centos 7 PostgreSQL一些简单问题以及解决办法
    centos 安装 java
    git push报错error: failed to push some refs to 'git@github.com:
    linux install beanstalkd
    centos7 执行一个数据库脚本创建项目中的数据库
  • 原文地址:https://www.cnblogs.com/greatverve/p/1554307.html
Copyright © 2011-2022 走看看