动态从数组中获取图片路径

如下代码,我先声明了两个图片路径数组,我想同过for循环的方式给每个div添加一个点击方法,并且替换他里面的图片,但是在替换图片时如何去吧路径携程动态的变量方式?就是代码中的icon_arr2.eqi。
代码有些臃肿还望各位大神将就着看,谢谢

 var icon_arr1 = ["images/per_center.png","images/per_meg.png","images/per_work.png","images/case_center.png"] var icon_arr2 = ["images/per_center2.png","images/per_meg2.png","images/per_work2.png","images/case_center2.png"] var a=$".xee_percenter"; forvar i = 0;i<a.length;i++{ a.eqi.clickfunction{ $this.css"background-color","#8e8e8f"; $this.find"img".attr"src",icon_arr2i//就是这里无效,该如何写才对 $this.find"a".css"color","white"; $this.css"border-left","5px solid #f08512"; $this.siblings".xee_percenter".css"background-color","#ffffff" $this.siblings".xee_percenter".css"border-left","none" $this.siblings".xee_percenter".find"a".css"color","#777777" } }

icon_arr2[i]
圆括号换成方括号

方括号写成圆括号的问题楼上有人提了,这里说下代码的优化。
绑定事件处理函数用on;
切换css样式推荐用css类,也可用对象字面量的写法:css{"color":"red","font-size":"20px"}

发表评论

电子邮件地址不会被公开。 必填项已用*标注