js函数调用问题 for(t=0;t <11;t++) { z=a[t]; document.getElementById(a[t].toString()).onmouseout=function(){menu1_change1(z);}; 这句调用不成功,如果把z换成常量,就能调用成功,不知问什么?请大家指教 } } 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 document.getElementById(a[t]).onmouseout= function(){eval("menu1_change1('" + z +"')");}; 问题出在这里:定义 var a=[]; <BODY onload="open_menu()"><div id="menu_1_a_1" style="width:200px;background-color:yellow;height:30px;">sssss</div><div id="menu_2_a_1" style="width:200px;background-color:red;height:30px;">sssss</div><div id="menu_2_a_2" style="width:200px;background-color:yellow;height:30px;">sssss</div><div id="menu_2_a_3" style="width:200px;background-color:red;height:30px;">sssss</div><div id="menu_2_a_4" style="width:200px;background-color:yellow;height:30px;">sssss</div><div id="menu_2_a_5" style="width:200px;background-color:red;height:30px;">sssss</div><div id="menu_2_a_6" style="width:200px;background-color:yellow;height:30px;">sssss</div><div id="menu_2_a_7" style="width:200px;background-color:red;height:30px;">sssss</div><div id="menu_2_a_8" style="width:200px;background-color:yellow;height:30px;">sssss</div><div id="menu_2_a_9" style="width:200px;background-color:red;height:30px;">sssss</div><div id="menu_2_a_10" style="width:200px;background-color:yellow;height:30px;">sssss</div> <script> function menu1_change1(menu) { alert(menu); document.getElementById(menu).style.backgroundColor="#ffffff"; document.getElementById(menu).style.borderTop="0px"; document.getElementById(menu).style.borderBottom="0px"; } function open_menu() { //alert(document.getElementById("menu_1_a_1").outerHTML); var a=[]; a[0]="menu_1_a_1"; a[1]="menu_2_a_1"; a[2]="menu_2_a_2"; a[3]="menu_2_a_3"; a[4]="menu_2_a_4"; a[5]="menu_2_a_5"; a[6]="menu_2_a_6"; a[7]="menu_2_a_7"; a[8]="menu_2_a_8"; a[9]="menu_2_a_9"; a[10]="menu_2_a_10"; for(var t=0;t <11;t++) { z=a[t]; document.getElementById(a[t]).onmouseout=function(){menu1_change1(z);}; //这句调用不成功,如果把z换成常量,就能调用成功,不知问什么?请大家指教 } } </script> </BODY> 同意楼上,你没定义数组a,加上var a=[];就可以吧 另外在循环里面加上这个估计能实现你的效果 for(t=0;t <11;t++) { (function () { var z=a[t]; document.getElementById(z).onmouseout=function(){menu1_change1(z);}; } )(); } 不是不成功,是每次调用 t总等于 menu_2_a_10这样改下for(t=0;t <11;t++) { z=a[t]; document.getElementById(a[t]).onmouseout=(function(z){ // 这句调用不成功,如果把z换成常量,就能调用成功,不知问什么?请大家指教 return function (){ menu1_change1(z); } })(z); } 写错了,是 z总等于 menu_2_a_10 写错了,是 z总等于 menu_2_a_10 请教;打开图片为何先出现几秒马赛克才能变清晰 (function(window,window.a))() 问个关于showModelessDialog的问题! 求一段访问页面有时间限制的Javascript 求source 只用html+javascript能制作统计图吗? 哪儿错了? javascript简单小问,在线等待,马上给分! 比方说1个下拉菜单。。点击哪个就弹出什么内容 求大神解决网页加载问题 求这个鼠标移动到图片上显示浮动层的图片——JS的效果 如何获取图片的title值
定义 var a=[];
<div id="menu_1_a_1" style="width:200px;background-color:yellow;height:30px;">sssss</div>
<div id="menu_2_a_1" style="width:200px;background-color:red;height:30px;">sssss</div>
<div id="menu_2_a_2" style="width:200px;background-color:yellow;height:30px;">sssss</div>
<div id="menu_2_a_3" style="width:200px;background-color:red;height:30px;">sssss</div>
<div id="menu_2_a_4" style="width:200px;background-color:yellow;height:30px;">sssss</div>
<div id="menu_2_a_5" style="width:200px;background-color:red;height:30px;">sssss</div>
<div id="menu_2_a_6" style="width:200px;background-color:yellow;height:30px;">sssss</div>
<div id="menu_2_a_7" style="width:200px;background-color:red;height:30px;">sssss</div>
<div id="menu_2_a_8" style="width:200px;background-color:yellow;height:30px;">sssss</div>
<div id="menu_2_a_9" style="width:200px;background-color:red;height:30px;">sssss</div>
<div id="menu_2_a_10" style="width:200px;background-color:yellow;height:30px;">sssss</div>
<script>
function menu1_change1(menu)
{
alert(menu);
document.getElementById(menu).style.backgroundColor="#ffffff";
document.getElementById(menu).style.borderTop="0px";
document.getElementById(menu).style.borderBottom="0px";
} function open_menu()
{ //alert(document.getElementById("menu_1_a_1").outerHTML);
var a=[];
a[0]="menu_1_a_1";
a[1]="menu_2_a_1";
a[2]="menu_2_a_2";
a[3]="menu_2_a_3";
a[4]="menu_2_a_4";
a[5]="menu_2_a_5";
a[6]="menu_2_a_6";
a[7]="menu_2_a_7";
a[8]="menu_2_a_8";
a[9]="menu_2_a_9";
a[10]="menu_2_a_10";
for(var t=0;t <11;t++)
{
z=a[t];
document.getElementById(a[t]).onmouseout=function(){menu1_change1(z);}; //这句调用不成功,如果把z换成常量,就能调用成功,不知问什么?请大家指教 }
}
</script>
</BODY>
for(t=0;t <11;t++)
{
(function ()
{
var z=a[t];
document.getElementById(z).onmouseout=function(){menu1_change1(z);};
}
)();
}
for(t=0;t <11;t++)
{
z=a[t];
document.getElementById(a[t]).onmouseout=(function(z){ // 这句调用不成功,如果把z换成常量,就能调用成功,不知问什么?请大家指教
return function (){
menu1_change1(z);
}
})(z);
}