日期:2014-05-20  浏览次数:20434 次

document.getElementById()里面能放参数吗?
我有3个div每次鼠标点上去的时候都会调用JS函数。
function   ok(){
document.getElementBuId( "aaa ").style.background= "red ";
document.getElementById( "bbb ").style.background= "white ";
document.getElementById( "ccc ").style.background= "white ";
}
我能不的在里面只写一句话,根据参数来判断是哪个控件呢?

------解决方案--------------------
可以

var a= "aaa "

document.getElementBuId(a).style.background= "red ";
------解决方案--------------------
function ok(theId){
document.getElementBuId(theId).style.background= "red ";

}

------解决方案--------------------
function setColor(theID, strColor)
{
document.getElementBuId(theId).style.background = strColor;
}