<![CDATA[Stri's Blog]]> http://www.striblog.com/ 2010-9-5 6:15:42 Blog zh-cn Copyright (C),2009, Stri.PC <![CDATA[关联数组]]> http://www.striblog.com/?p=30 点符号与方括号
在数组中

var str=[1,2,3];
str[1]

在对象中
var fun={
x:function(){
},
y:function(){
}}

fun.x();可以执行,fun['x']()也可以执行
具体可以看下面的实例


在CSS中的可以应用,例如下面
style.+得是它的一个属性.如果写成
style.stylename就错误了.应该它不是style的属性.
<select name="textAlign" id="select">
<option value="left">left</option>
<option value="right">right</option>
<option value="center">center</option>
</select>
<div id="box">thinkpad</div>
<script type="text/javascript">
function getValue(){
var styleName=this.name,
styleValue=this.value;
document.getElementById("box").style[styleName]=styleValue;
document.getElementById("box").innerHTML=styleValue;

}
document.getElementById("select").onchange=getValue;
</script>


还有其它应用,
如果在表单验证中.把常用的验证几项写成一个函数,在input上中个非w3c属性,通过dom查找这个非属性,来决定用那一个验证函数


这样的做法显然不能通过w3c验证.不过在实用中却很中用.]]>
http://www.striblog.com/?p=30#comment 544 Thu, 26 Nov 2009 00:18:56 +0800 http://www.striblog.com/?p=30