js中字符串转化成对象名或者变量名

我直接发源码
<script type="text/javascript">
function rizeto(img,imgWidth,imgHeight)
{
img.style.width=imgWidth;
img.style.height=imgHeight;
}
</script>
现在是这样调用的rizeto("imgname",150,150)无法执行,识别不了Iimg,,imagename是这个IMAGE的ID和Name

function rizeto(img,imgWidth,imgHeight){
var o=document.getElementById(img);
o.style.width=imgWidth;
o.style.height=imgHeight;
}追问

兄弟,我应该怎么谢你???请说!你这个方法我怎么就没想到呢????

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-04-30
[“M”+] =真哦! JS!追问

不明白,我直接发源码

function rizeto(img,imgWidth,imgHeight)
{
img.style.width=imgWidth;
img.style.height=imgHeight;
}

现在是这样调用的rizeto("imgname",150,150)无法执行,识别不了Image,imgname是这个IMAGE的ID和Name

相似回答