javascript數組練習
文章來源:365jz.com 點擊數:
300 更新時間:2009-10-07 10:57
參與評論
<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>
如對本文有疑問,請?zhí)峤坏浇涣髡搲瑥V大熱心網友會為你解答??! 點擊進入論壇
------分隔線----------------------------