<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title><![CDATA[海峡IT网 - Javascript]]></title>
<link>http://www.haixiait.com/</link>
<description><![CDATA[haixiaIT.COM_创造价值,传播技术,分享快乐!]]></description>
<language>zh-cn</language>
<copyright><![CDATA[Copyright 2005 PBlog3 v2.8]]></copyright>
<webMaster><![CDATA[airzen@126.com(airzen)]]></webMaster>
<generator>PBlog2 v2.4</generator> 
<image>
	<title>海峡IT网</title>
	<url>http://www.haixiait.com/images/logos.gif</url>
	<link>http://www.haixiait.com/</link>
	<description>海峡IT网</description>
</image>

			<item>
			<link>http://www.haixiait.com/article.asp?id=394</link>
			<title><![CDATA[url转义字符]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Thu,24 Jun 2010 16:07:59 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=394</guid>
		<description><![CDATA[<p>web 开发中通问好（？）方式在浏览器地址栏中传值时。浏览器是通过&ldquo;&amp;&rdquo;来区分问号后的参数个数的。 如果出现传值参数中带有&ldquo;&amp;&rdquo;时，在接受页面就会出现错误，类似如下请求路径：/next.jsp?param1=hendhs89&amp;furej &amp; param2=sss</p>
<p>参数param1中含有转义字符&ldquo;&amp;&rdquo; ，这样会导致被请求页的参数接收错误。</p>
<p>在传值前&nbsp;通过 java.net.URLEncoder.encode(param1) 编码处理后，可将转义字符转为16进制;</p>
<p>&nbsp;1.&nbsp;&nbsp; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; URL&nbsp;&nbsp; 中+号表示空格&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %2B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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %3D</p>]]></description>
		</item>
		
			<item>
			<link>http://www.haixiait.com/article.asp?id=365</link>
			<title><![CDATA[jquery选择框后面的标签内容]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Fri,25 Sep 2009 18:40:06 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=365</guid>
		<description><![CDATA[<p>&nbsp;&nbsp;&lt;input id=&quot;RadioDeliverType_0&quot; type=&quot;radio&quot; name=&quot;RadioDeliverType&quot; value=&quot;3&quot; checked=&quot;checked&quot; /&gt;&lt;label for=&quot;RadioDeliverType_0&quot;&gt;中国邮政EMS&lt;/label&gt;<br />
&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&lt;input id=&quot;RadioDeliverType_1&quot; type=&quot;radio&quot; name=&quot;RadioDeliverType&quot; value=&quot;1&quot; onclick=&quot;javascript:setTimeout('__doPostBack(\'RadioDeliverType$1\',\'\')', 0)&quot; /&gt;&lt;label for=&quot;RadioDeliverType_1&quot;&gt;韵达快运&lt;/label&gt;</p>
<p>&nbsp;&lt;script type=&quot;text/javascript&quot;&gt;<br />
&nbsp;alert($(&quot;input:checked[name='RadioDeliverType']&quot;).eq(0).next().text()); //得到中国邮政EMS</p>
<p>&nbsp;&nbsp; &lt;/script&gt;</p>
<p>&nbsp;</p>]]></description>
		</item>
		
			<item>
			<link>http://www.haixiait.com/article.asp?id=364</link>
			<title><![CDATA[添加与删除Option对象]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Thu,24 Sep 2009 16:45:56 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=364</guid>
		<description><![CDATA[<p>&lt;html&gt; <br />
&lt;head&gt; <br />
&lt;title&gt;添加与删除Option对象&lt;/title&gt; <br />
&lt;script language=&quot;javascript&quot;&gt; <br />
// 添加选项 <br />
function addOption(obj,txt,val){ <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; // 建立Option对象 <br />
&nbsp;&nbsp;&nbsp; var objOption = new Option(txt,val); <br />
&nbsp;obj.options[obj.options.length] = objOption;</p>
<p>} <br />
// 删除选项 <br />
function deleteOption(obj){</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj.remove(obj.selectedIndex);</p>
<p>} <br />
// 显示选项信息 <br />
function showOption(obj){ <br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; var name = obj.options[obj.selectedIndex].text; <br />
&nbsp;&nbsp;&nbsp; var value = obj.options[obj.selectedIndex].value; <br />
&nbsp;&nbsp;&nbsp; return (name + &quot; = &quot; + value);</p>
<p>} <br />
// 全清<br />
function removeAll(obj)<br />
{&nbsp;max = obj.options.length;<br />
&nbsp;for(var i=0;i&lt;max;i++)<br />
&nbsp;{<br />
&nbsp;&nbsp;obj.remove(0);<br />
&nbsp;}<br />
}</p>
<p><br />
&lt;/script&gt; <br />
&lt;/head&gt; <br />
&lt;body&gt; <br />
&lt;h2&gt;添加与删除Option对象&lt;/h2&gt; <br />
&lt;hr&gt; <br />
&lt;form name=&quot;myForm&quot;&gt; <br />
&lt;select name=&quot;mySelect&quot; ID=&quot;mySelect&quot; size=&quot;10&quot; style=&quot;width:250px;&quot; multiple&gt; <br />
&lt;option value=&quot;中国&quot; Selected&gt;中国&lt;/option&gt; <br />
&lt;option value=&quot;日本&quot;&gt;日本&lt;/option&gt; <br />
&lt;option value=&quot;美国&quot;&gt;美国&lt;/option&gt; <br />
&lt;/select&gt; <br />
&lt;input type=&quot;button&quot; onclick=&quot;showOption(this.form.mySelect)&quot; value=&quot;显示&quot;&gt; <br />
&lt;input type=&quot;button&quot; onclick=&quot;removeAll(this.form.mySelect)&quot; value=&quot;全清&quot;&gt;<br />
&lt;input type=&quot;button&quot; onclick=&quot;deleteOption(this.form.mySelect)&quot; value=&quot;删除所选&quot;&gt;</p>
<p>&lt;input type=&quot;button&quot; onclick=&quot;addOption(this.form.mySelect,'海峡IT网,'haixiait')&quot; value=&quot;添加&quot;&gt;</p>
<p>&lt;/form&gt; <br />
&lt;/body&gt; <br />
&lt;/html&gt;</p>]]></description>
		</item>
		
			<item>
			<link>http://www.haixiait.com/article.asp?id=362</link>
			<title><![CDATA[输入框中的内容输入限制JS，自动过滤非允许的内容]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Mon,21 Sep 2009 14:31:45 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=362</guid>
		<description><![CDATA[<p>JS判断只能是数字和小数点</p>
<p><strong>1.文本框只能输入数字代码(小数点也不能输入)</strong><br />
&lt;input onkeyup=&quot;this.value=this.value.replace(/\D/g,'')&quot; onafterpaste=&quot;this.value=this.value.replace(/\D/g,'')&quot;&gt;</p>
<p><strong>2.只能输入数字,能输小数点.</strong><br />
&lt;input onkeyup=&quot;if(isNaN(value))execCommand('undo')&quot; onafterpaste=&quot;if(isNaN(value))execCommand('undo')&quot;&gt;<br />
&lt;input name=txt1 onchange=&quot;if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}&quot;&gt;</p>
<p><strong>3.数字和小数点方法二</strong><br />
&lt;input type=text t_value=&quot;&quot; o_value=&quot;&quot; onkeypress=&quot;if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value&quot; onkeyup=&quot;if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value&quot; onblur=&quot;if(!this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/))this.value=this.o_value;else{if(this.value.match(/^\.\d+$/))this.value=0+this.value;if(this.value.match(/^\.$/))this.value=0;this.o_value=this.value}&quot;&gt;</p>
<p><strong>4.只能输入字母和汉字</strong><br />
&lt;input onkeyup=&quot;value=value.replace(/[\d]/g,'') &quot;onbeforepaste=&quot;clipboardData.setData('text',clipboardData.getData('text').replace(/[\d]/g,''))&quot; maxlength=10 name=&quot;Numbers&quot;&gt;</p>
<p><strong>5.只能输入英文字母和数字,不能输入中文</strong><br />
&lt;input onkeyup=&quot;value=value.replace(/[^\w\.\/]/ig,'')&quot;&gt;</p>
<p><strong>6.只能输入数字和英文</strong>&lt;font color=&quot;Red&quot;&gt;chun&lt;/font&gt;<br />
&lt;input onKeyUp=&quot;value=value.replace(/[^\d|chun]/g,'')&quot;&gt;</p>
<p><strong>7.小数点后只能有最多两位(数字,中文都可输入),不能输入字母和运算符号:</strong><br />
&lt;input onKeyPress=&quot;if((event.keyCode&lt;48 || event.keyCode&gt;57) &amp;&amp; event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false&quot;&gt;</p>
<p><strong>8.小数点后只能有最多两位(数字,字母,中文都可输入),可以输入运算符号:</strong><br />
&lt;input onkeyup=&quot;this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')&quot;&gt;</p>
<p>只能是数字和小数点和加减乘際</p>
<p>onkeypress=&quot;return event.keyCode&gt;=4&amp;&amp;event.keyCode&lt;=57&quot;</p>]]></description>
		</item>
		
			<item>
			<link>http://www.haixiait.com/article.asp?id=361</link>
			<title><![CDATA[flash as2.0中被加载的子影片不影响主影片的root锁定问题]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Wed,16 Sep 2009 14:41:18 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=361</guid>
		<description><![CDATA[<p>在被加载的子影片.swf的第一帧中指定</p>
<p>_lockroot=true;</p>
<p>这样，如果其它影片加载他的时候，不会影响到主影片，感谢<a target="_blank" href="http://www.p-boy.cn">动力男孩</a>powerboy的帮助</p>
<p>&nbsp;</p>]]></description>
		</item>
		
			<item>
			<link>http://www.haixiait.com/article.asp?id=359</link>
			<title><![CDATA[兼容IE/FF鼠标坐标滑动的一段代码]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Thu,03 Sep 2009 09:05:38 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=359</guid>
		<description><![CDATA[<p>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>&quot;&gt;<br />
&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>&quot; &gt;<br />
&lt;head&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;title&gt;Untitled Page&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;div id=&quot;showCursor&quot; style=&quot;position:absolute;&quot;&gt;&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;<br />
var showCursorDiv=document.getElementById(&quot;showCursor&quot;);<br />
window.document.onmousemove=function(evt){<br />
&nbsp;&nbsp;&nbsp; evt=evt || window.event;<br />
&nbsp;&nbsp;&nbsp; showCursorDiv.style.left=evt.clientX+&quot;px&quot;;<br />
&nbsp;&nbsp;&nbsp; showCursorDiv.style.top=evt.clientY+&quot;px&quot;;<br />
&nbsp;&nbsp;&nbsp; showCursorDiv.innerHTML=&quot;X:&quot; + evt.clientX&nbsp; + &quot;&nbsp; Y:&quot; + evt.clientY;&nbsp;&nbsp; <br />
}<br />
&lt;/script&gt;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>如果用于某个图片垂直随鼠标滑动</p>
<p>var showCursorDiv=document.getElementById(&quot;logo&quot;);<br />
window.document.onmousemove=function(evt){<br />
&nbsp;&nbsp;&nbsp; evt=evt || window.event;<br />
&nbsp;&nbsp;&nbsp; base_y = evt.clientY;<br />
&nbsp;if(base_y&gt;=85 &amp;&amp; base_y&lt;=(663 -144)){<br />
&nbsp;&nbsp;showCursorDiv.style.top=base_y+&quot;px&quot;;<br />
&nbsp;}<br />
&nbsp;<br />
}</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></description>
		</item>
		
			<item>
			<link>http://www.haixiait.com/article.asp?id=355</link>
			<title><![CDATA[认识Javascript数组-数组元素的操作]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Fri,21 Aug 2009 10:09:22 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=355</guid>
		<description><![CDATA[<p><strong><font color="#ff0000">2.数组元素的操作</font></strong></p>
<p>上面已经说过，可以通过 数组[下标] 来读写元素</p>
<p>下标的范围是 0 &ndash; (23(上标2) -1)，当下标是负数、浮点甚至布尔值的时候，数组会自动转换为对象类型，例如</p>
<p><span class="code"><font color="#000000">var b&nbsp;&nbsp;&nbsp; = new Array();<br />
b[2.2]&nbsp;&nbsp;&nbsp; = &quot;XXXXX&quot;;<br />
alert(b[2.2]);&nbsp; //-&gt; XXXXX </font></span></p>
<p>此时相当于b[&ldquo;2.2&rdquo;]&nbsp; = &ldquo;XXXXX&rdquo;</p>
<p><strong>2.1数组的循环</strong></p>
<p><span class="code"><font color="#000000">var a = [1,2,3,4,5,6];<br />
for(var i =0; i&lt;a.length; i++){<br />
alert(a[i]);<br />
}</font></span></p>
<p>这是最常用的，历遍数组，代码将依次弹出1至6</p>
<p>还有一种常用的</p>
<p><span class="code"><font color="#000000">var a = [1,2,3,4,5,6];<br />
for(var e in a){<br />
alert(e);<br />
} </font></span></p>
<p>还是依次弹出1至6，for&hellip;in是历遍对象（数组是特殊的对象）对象，用在数组上，因为数组没有属性名，所以直接输出值，这结构语句用在对象上，例如下面</p>
<p><span class="code"><font color="#000000">var a = {x:1,y:2,z:3};<br />
for(var e in a){<br />
alert(e&nbsp;&nbsp;&nbsp; + &quot;:&quot; + a[e]);<br />
} </font></span></p>
<p>此时e取到的是属性名，即 x、y、x，而要取得值，则采用 数组名[属性]，所以 a[e] 等同于 a[&ldquo;x&rdquo;]、a[&ldquo;y&rdquo;]、a[&ldquo;z&rdquo;]</p>
<p><strong>2.2数组常用函数</strong></p>
<p><strong>concat</strong></p>
<p>在现有数组后面追加数组，并返回新数组，不影响现有数组</p>
<p><span class="code"><font color="#000000">var a = [123];<br />
var b = &quot;sunnycat&quot;;<br />
var c =&nbsp;&nbsp;&nbsp; [&quot;www&quot;,21,&quot;ido&quot;];<br />
var d = {x:3.14, y:&quot;SK&quot;};<br />
var e = [1,2,3,4,[5,6,[7,8]]];<br />
alert(a.concat(b));&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 123,sunnycat<br />
alert(a);&nbsp; //&nbsp;&nbsp;&nbsp; -&gt; 123<br />
alert(b.concat(c, d));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; sunnycatwww,21,ido[object&nbsp;&nbsp;&nbsp; Object]<br />
alert(c.concat(b));&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; www,21,ido,sunnycat<br />
alert(e.concat(11,22,33).join(&quot; #&nbsp;&nbsp;&nbsp; &quot;));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 1 # 2 # 3&nbsp;&nbsp;&nbsp; # 4 # 5,6,7,8 # 11 # 22 # 33</font></span></p>
<p>需要注意的是只能用于数组或字符串，如果被连接（前面的a）的是数值、布尔值、对象，就会报错，字符串连接数组时，字符串会跟数组首元素拼接成新元素，而数组连接字符串则会追加新元素（这点我也不清楚原委，知情者请透露），对于数组里面包含数组、对象的，连接后保持原样</p>
<p><strong>join</strong></p>
<p>用指定间隔符连起来，把数组转为字符串</p>
<p><span class="code"><font color="#000000">var a = ['a','b','c','d','e','f','g'];<br />
lert(a.join(&quot;,&quot;));&nbsp;&nbsp; // -&gt; a,b,c,d,e,f,g 相当于a.toString()<br />
alert(a.join(&quot; x &quot;));&nbsp; // -&gt; a x b x c x d x e x f x g</font></span></p>
<p>这个很容易理解，但需要注意的是只转换一维数组里面，如果数组里面还有数组，将不是采用join指定的字符串接，而是采用默认的toString()，例如</p>
<p><span class="code"><font color="#000000">var a =&nbsp;&nbsp;&nbsp; ['a','b','c','d','e','f','g',[11,22,33]];<br />
alert(a.join(&quot; * &quot;));&nbsp; // -&gt; a * b * c * d * e * f * g *&nbsp;&nbsp;&nbsp; 11,22,33</font></span></p>
<p>数组里面的数组，并没用 * 连接</p>
<p><strong>pop</strong></p>
<p>删除数组最后一个元素，并返回该元素</p>
<p><span class="code"><font color="#000000">var a =&nbsp;&nbsp;&nbsp; [&quot;aa&quot;,&quot;bb&quot;,&quot;cc&quot;];<br />
document.write(a.pop());&nbsp;&nbsp;&nbsp; // -&gt; cc<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; aa, bb</font></span></p>
<p>如果数组为空，则返回undefined</p>
<p><strong>push</strong></p>
<p>往数组后面添加数组，并返回数组新长度</p>
<p><span class="code"><font color="#000000">var a =&nbsp;&nbsp;&nbsp; [&quot;aa&quot;,&quot;bb&quot;,&quot;cc&quot;];<br />
document.write(a.push(&quot;dd&quot;));&nbsp;&nbsp;&nbsp; // -&gt; 4<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; aa,bb,cc,dd<br />
document.write(a.push([1,2,3]));&nbsp; // -&gt; 5<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; aa,bb,cc,dd,1,2,3</font></span></p>
<p>跟concat的区别在于，concat不影响原数组，直接返回新数组，而push则直接修改原数组，返回的是数组新长度</p>
<p><strong>sort</strong></p>
<p>数组排序，先看个例子</p>
<p><span class="code"><font color="#000000">var a = [11,2,3,33445,5654,654,&quot;asd&quot;,&quot;b&quot;];<br />
alert(a.sort()); // -&gt; 11,2,3,33445,5654,654,asd,b</font></span></p>
<p>结果是不是很意外，没错，排序并不是按整型大小，而是字符串对比，就是取第一个字符的ANSI码对比，小的排前面，相同的话取第二个字符再比，如果要按整型数值比较，可以这样</p>
<p><span class="code"><font color="#000000">var a = [11,2,3,33445,5654,654];<br />
a.sort(function(a,b) {<br />
return a - b;<br />
});<br />
alert(a);&nbsp; //&nbsp;&nbsp;&nbsp; -&gt; 2,3,11,654,5654,33445</font></span></p>
<p>sort()方法有个可选参数，就是代码里的function，这是个简单的例子，不可对非数字进行排序，非数字需要多做判断，这里就不多讲</p>
<p><strong>reverse</strong></p>
<p>对数组进行反排序跟，sort()一样，取第一字符ASCII值进行比较</p>
<p><span class="code"><font color="#000000">var a = [11,3,5,66,4];<br />
alert(a.reverse());&nbsp; // -&gt; 4,66,5,3,11</font></span></p>
<p>如果数组里面还包含数组，则当为对象处理，并不会把元素解出来</p>
<p><span class="code"><font color="#000000">&gt;var a = ['a','b','c','d','e','f','g',[4,11,33]];<br />
alert(a.reverse());&nbsp; // -&gt; 4,11,33,g,f,e,d,c,b,a<br />
alert(a.join(&quot; * &quot;));&nbsp; // -&gt; 4,11,33 * g * f * e * d * c * b * a</font></span></p>
<p>按理应该是11排最后面，因为这里把 4,11,33 当做完整的对象比较，所以被排在第一位。看不明白的话，用join()串起来，就明了多</p>
<p><strong>shift</strong></p>
<p>删除数组第一个元素，并返回该元素，跟pop差不多</p>
<p><span class="code"><font color="#000000">var a =&nbsp;&nbsp;&nbsp; [&quot;aa&quot;,&quot;bb&quot;,&quot;cc&quot;];<br />
document.write(a.shift());&nbsp;&nbsp; // -&gt; aa<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; bb,cc</font></span></p>
<p>当数组为空时，返回undefined</p>
<p><strong>unshift</strong></p>
<p>跟shift相反，往数组最前面添加元素，并返回数组新长度</p>
<p><span class="code"><font color="#000000">var a =&nbsp;&nbsp;&nbsp; [&quot;aa&quot;,&quot;bb&quot;,&quot;cc&quot;];<br />
document.write(a.unshift(11));&nbsp;&nbsp; // -&gt; 4 注：IE下返回undefined<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 11,aa,bb,cc<br />
document.write(a.unshift([11,22]));&nbsp;&nbsp; // -&gt; 5<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 11,22,11,aa,bb,cc<br />
document.write(a.unshift(&quot;cat&quot;));&nbsp; // -&gt; 6<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; cat,11,22,11,aa,bb,cc</font></span></p>
<p>注意该方法，在IE下将返回undefined，貌似微软的bug，我在firefox下则能正确发挥数组新长度</p>
<p><strong>slice</strong></p>
<p>返回数组片段</p>
<p><span class="code"><font color="#000000">var a = ['a','b','c','d','e','f','g'];<br />
alert(a.slice(1,2));&nbsp; // -&gt; b<br />
alert(a.slice(2));&nbsp;&nbsp;&nbsp; // -&gt; c,d,e,f,g<br />
alert(a.slice(-4));&nbsp;&nbsp; // -&gt; d,e,f,g<br />
alert(a.slice(-2,-6));&nbsp;&nbsp;&nbsp; // -&gt; 空</font></span></p>
<p>a.slice(1,2)，从下标为1开始，到下标为2之间的数，注意并不包括下标为2的元素<br />
如果只有一个参数，则默认到数组最后<br />
-4是表示倒数第4个元素，所以返回倒数的四个元素<br />
最后一行，从倒数第2开始，因为是往后截取，所以显然取不到前面的元素，所以返回空数组，如果改成&nbsp; a.slice(-6,-2) 则返回b,c,d,e</p>
<p><strong>splice</strong></p>
<p>从数组删除某片段的元素，并返回删除的元素</p>
<p><span class="code"><font color="#000000">var a = [1,2,3,4,5,6,7,8,9];<br />
document.write(a.splice(3,2));&nbsp;&nbsp;&nbsp; // -&gt; 4,5<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 1,2,3,6,7,8,9<br />
document.write(a.splice(4));&nbsp; // -&gt; 7,8,9 注：IE下返回空<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 1,2,3,6<br />
document.write(a.splice(0,1));&nbsp;&nbsp;&nbsp; // -&gt; 1<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 2,3,6<br />
document.write(a.splice(1,1,[&quot;aa&quot;,&quot;bb&quot;,&quot;cc&quot;]));&nbsp;&nbsp; // -&gt; 3<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 2,aa,bb,cc,6,7,8,9<br />
document.write(a.splice(1,2,&quot;ee&quot;).join(&quot;#&quot;)); // -&gt; aa,bb,cc#6<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 2,ee,7,8,9<br />
document.write(a.splice(1,2,&quot;cc&quot;,&quot;aa&quot;,&quot;tt&quot;).join(&quot;#&quot;));&nbsp; // -&gt; ee#7<br />
document.write(a);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // -&gt; 2,cc,aa,tt,8,9</font></span></p>
<p>注意该方法在IE下，第二个参数是必须的，不填则默认为0，例如a.splice(4)，在IE下则返回空，效果等同于a.splice(4,0)</p>
<p><strong>toString</strong></p>
<p>把数组转为字符串，不只数组，所有对象均可使用该方法</p>
<p><span class="code"><font color="#000000">var a =&nbsp;&nbsp;&nbsp; [5,6,7,8,9,[&quot;A&quot;,&quot;BB&quot;],100];<br />
document.write(a.toString());&nbsp;&nbsp;&nbsp; // -&gt; 5,6,7,8,9,A,BB,100<br />
var b = new Date()<br />
document.write(b.toString());&nbsp;&nbsp;&nbsp; // -&gt; Sat Aug 8 17:08:32 UTC+0800&nbsp;&nbsp;&nbsp; 2009<br />
var c = function(s){<br />
alert(s);<br />
}<br />
document.write(c.toString());&nbsp;&nbsp;&nbsp; // -&gt; function(s){ alert(s); }</font></span></p>
<p>布尔值则返回true或false，对象则返回[object objectname]<br />
相比join()方法，join()只对一维数组进行替换，而toString()则把整个数组（不管一维还是多维）完全平面化<br />
同时该方法可用于10进制、2进制、8进制、16进制转换，例如</p>
<p><span class="code"><font color="#000000">var a =&nbsp;&nbsp;&nbsp; [5,6,7,8,9,&quot;A&quot;,&quot;BB&quot;,100];<br />
for(var i=0; i&lt;a.length; i++){<br />
document.write(a[i].toString()&nbsp;&nbsp;&nbsp; + &quot; 的二进制是 &quot;&nbsp;&nbsp;&nbsp; + a[i].toString(2) + &quot; ，八进制是 &quot; + a[i].toString(8) + &quot; ，十六进制是 &quot; + a[i].toString(16));&nbsp; //&nbsp;&nbsp;&nbsp; -&gt; 4,5<br />
} </font></span></p>
<p>输出结果</p>
<p><span class="code"><font color="#000000">5 的二进制是 101 ，八进制是 5 ，十六进制是 5<br />
6 的二进制是 110 ，八进制是 6 ，十六进制是 6<br />
7 的二进制是 111 ，八进制是 7 ，十六进制是 7<br />
8 的二进制是 1000 ，八进制是 10 ，十六进制是 8<br />
9 的二进制是 1001 ，八进制是 11 ，十六进制是 9<br />
A 的二进制是 A ，八进制是 A ，十六进制是 A<br />
BB 的二进制是 BB ，八进制是 BB ，十六进制是 BB<br />
100 的二进制是 1100100 ，八进制是 144 ，十六进制是 64 </font></span></p>
<p>转换只能在元素进行，如果对整个数组进行转换，则原封不动返回该数组</p>
<p><strong>toLocaleString</strong></p>
<p>返回本地格式字符串，主要用在Date对象上</p>
<p><span class="code"><font color="#000000">var a = new Date();<br />
document.write(a.toString());&nbsp;&nbsp;&nbsp; // -&gt; Sat Aug 8 17:28:36 UTC+0800&nbsp;&nbsp;&nbsp; 2009<br />
document.write(a.toLocaleString());&nbsp;&nbsp; // -&gt; 2009年8月8日 17:28:36<br />
document.write(a.toLocaleDateString());&nbsp;&nbsp; // -&gt; 2009年8月8日 </font></span></p>
<p>区别在于，toString()返回标准格式，toLocaleString()返回本地格式完整日期（在【控制面板】&gt;&gt;【区域和语言选项】，通过修改[时间]和[长日期]格式），toLocaleDateString()跟toLocaleString()一样，只是少了时间</p>
<p><strong>valueOf</strong></p>
<p>根据不同对象返回不同原始值，用于输出的话跟toString()差不多，但是toString()是返回string类型，而valueOf()是返回原对象类型</p>
<p><span class="code"><font color="#000000">var a = [1,2,3,[4,5,6,[7,8,9]]];<br />
var b = new Date();<br />
var c = true;<br />
var d = function(){<br />
alert(&quot;sunnycat&quot;);<br />
};<br />
document.write(a.valueOf());&nbsp;&nbsp;&nbsp; // -&gt; 1,2,3,4,5,6,7,8,9<br />
document.write(typeof (a.valueOf()));&nbsp; // -&gt; object<br />
document.write(b.valueOf());&nbsp;&nbsp;&nbsp; // -&gt; 1249874470052<br />
document.write(typeof(b.valueOf()));&nbsp; // -&gt; number<br />
document.write(c.valueOf());&nbsp;&nbsp;&nbsp; // -&gt; true<br />
document.write(typeof(c.valueOf()));&nbsp; // -&gt; boolean<br />
document.write(d.valueOf());&nbsp;&nbsp;&nbsp; // -&gt; function () {&nbsp;&nbsp;&nbsp; alert(&quot;sunnycat&quot;); }<br />
document.write(typeof(d.valueOf()));&nbsp; // -&gt; function</font></span></p>
<p>数组也是对象，所以typeof&nbsp; (a.valueOf())返回object，返回的依然是个多维数组</p>
<p><span class="code"><font color="#000000">var a = [1,2,3,[4,5,6,[7,8,9]]];<br />
var aa = a.valueOf();<br />
document.write(aa[3][3][1]); // -&gt; 8 </font></span></p>
<p>Date对象返回的是距离1970年1月1日的毫秒数，<br />
Math和Error对象没有valueOf方法.</p>
<p>*完*</p>]]></description>
		</item>
		
			<item>
			<link>http://www.haixiait.com/article.asp?id=354</link>
			<title><![CDATA[认识Javascript数组--认识数组]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Fri,21 Aug 2009 10:06:12 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=354</guid>
		<description><![CDATA[<p><strong><font color="#ff0000">1.认识数组</font></strong></p>
<p>数组就是某类数据的集合，数据类型可以是整型、字符串、甚至是对象<br />
Javascript不支持多维数组，但是因为数组里面可以包含对象（数组也是一个对象），所以数组可以通过相互嵌套实现类似多维数组的功能</p>
<p><strong>1.1 定义数组</strong></p>
<p>声明有10个元素的数组</p>
<p><span class="code"><font color="#000000">var a = new Array(10); </font></span></p>
<p>此时为a已经开辟了内存空间，包含10个元素，用数组名称加 [下标] 来调用，例如 a[2] 但此时元素并未初始化，调用将返回 undefined</p>
<p>以下代码定义了个可变数组，并进行赋值</p>
<p><span class="code"><font color="#000000">var a = new Array();<br />
a[0] = 10;<br />
a[1] = &quot;aaa&quot;;<br />
a[2] = 12.6; </font></span></p>
<p>上面提过了，数组里面可以放对象，例如下面代码</p>
<p><span class="code"><font color="#000000">var a =&nbsp;&nbsp;&nbsp; new Array();<br />
a[0]&nbsp;&nbsp;&nbsp; = true;<br />
a[1]&nbsp;&nbsp;&nbsp; = document.getElementById(&quot;text&quot;);<br />
a[2]&nbsp;&nbsp;&nbsp; = {x:11, y:22};<br />
a[3]&nbsp;&nbsp;&nbsp; = new Array();</font></span></p>
<p>数组可以实例化的时候直接赋值，例如</p>
<p><span class="code"><font color="#000000">var a = new Array(1, 2, 3, 4, 5);<br />
var b = [1, 2, 3, 4, 5]; </font></span></p>
<p>a 和 b 都是数组，只不过b用了隐性声明，创建了另一个实例，此时如果用alert(a==b)将弹出false</p>
<p><strong>1.2 多维数组</strong></p>
<p>其实Javascript是不支持多维数组的，在asp里面可以用 dim a(10,3)来定义多维数组，在Javascript里面，如果用 var a = new Array(10,3) 将报错<br />
但是之前说过，数组里面可以包含对象，所以可以把数组里面的某个元素再声明为数组，例如</p>
<p><span class="code"><font color="#000000">var a = new Array();<br />
a[0] = new Array();<br />
a[0][0] = 1;<br />
alert(a[0][0]);&nbsp; //弹出 1 </font></span></p>
<p>声明的时候赋值</p>
<p><span class="code"><font color="#000000">var a = new Array([1,2,3], [4,5,6],&nbsp;&nbsp;&nbsp; [7,8,9]);<br />
var b = [[1,2,3], [4,5,6], [7,8,9]]; </font></span></p>
<p>效果一样，a采用常规实例化，b是隐性声明，结果都是生成一个多维数组</p>
<p><strong>1.3 Array literals</strong></p>
<p>这个还真不知中文怎么叫，文字数组？<br />
说到数组，不得不说到Array&nbsp; Literals，数组其实是特殊的对象，对象有特有属性和方法，通过 对象名.属性 、对象.方法() 来取值和调用，而数组是通过下标来取值，Array Literals跟数组有很多相似，都是某数据类型的集合，但是Array Literals从根本来说，是个对象，声明和调用，跟数组是有区别</p>
<p><span class="code"><font color="#000000">var aa = new Object();<br />
aa.x = &quot;cat&quot;;<br />
aa.y = &quot;sunny&quot;;<br />
alert(aa.x);&nbsp;&nbsp;&nbsp; //弹出cat </font></span></p>
<p>创建一个简单的对象，一般调用是通过aa.x，而如果当成Array&nbsp; literals的话，用alert(aa[&ldquo;x&rdquo;])一样会弹出cat</p>
<p><span class="code"><font color="#000000">var a = {x:&quot;cat&quot;,&nbsp;&nbsp;&nbsp; y:&quot;sunny&quot;};<br />
alert(a[&quot;y&quot;]);&nbsp; //弹出sunny</font></span></p>
<p>这是另一种创建对象的方法，结果是一样的。</p>]]></description>
		</item>
		
			<item>
			<link>http://www.haixiait.com/article.asp?id=351</link>
			<title><![CDATA[DIV,TEXTAREA内容同步联动显示]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Fri,07 Aug 2009 11:19:11 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=351</guid>
		<description><![CDATA[<p>&nbsp;&lt;textarea rows=&quot;5&quot; cols=&quot;7&quot; id=&quot;t1&quot; <strong><u>onscroll=&quot;document.getElementById('t2').scrollTop = this.scrollTop;document.getElementById('t2').scrollLeft = this.scrollLeft;&quot;</u></strong><u> </u>&gt;<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;&lt;/textarea&gt;</p>
<p><br />
&nbsp;&lt;textarea rows=&quot;5&quot; cols=&quot;7&quot; id=&quot;t2&quot; <strong><u>onscroll=&quot;document.getElementById('t1').scrollTop = this.scrollTop;document.getElementById('t1').scrollLeft = this.scrollLeft;&quot; </u></strong>&gt;<br />
&nbsp; 海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;海峡IT网，airzen ,http://www.haixiait.com<br />
&nbsp;&lt;/textarea&gt;</p>
<p>&nbsp;</p>
<p>同时对于DIV或其它容器标签均试用。</p>]]></description>
		</item>
		
			<item>
			<link>http://www.haixiait.com/article.asp?id=350</link>
			<title><![CDATA[JS获得当年月的第一天至月末区间字符串（闰年自适应）]]></title>
			<author>airzen@126.com(airzen)</author>
			<category><![CDATA[Javascript]]></category>
			<pubDate>Fri,07 Aug 2009 11:15:56 +0800</pubDate>
			<guid>http://www.haixiait.com/default.asp?id=350</guid>
		<description><![CDATA[<p>//获得当年月的第一天至月末区间字符串（闰年自适应）<br />
// start-第一天<br />
// end&nbsp; -最后一天<br />
function get_date_str(year,month,flag){<br />
&nbsp;var retv ='';<br />
&nbsp;if(flag=='start'){<br />
&nbsp;&nbsp;retv = year + '-' + month + '-01';<br />
&nbsp;}else if(flag=='end'){<br />
&nbsp;&nbsp;var&nbsp; day = new Date(year,month,0); <br />
&nbsp;&nbsp;retv = year + '-' + month + '-' + day.getDate();<br />
&nbsp;}<br />
&nbsp;<br />
&nbsp;return retv;<br />
&nbsp;<br />
}</p>
<p>调用月初 get_date_str(year,month,'start'),月末get_date_str(year,month,'end'),</p>
<p>&nbsp;</p>]]></description>
		</item>
		
</channel>
</rss>







