首页 新闻 会员 周边

js的setTimeout的问题

0
悬赏园豆:20 [已解决问题] 解决于 2011-01-03 15:17

请教一个setTimeout传递对象参数的问题,最好给举个例子,多谢.

setTimeout控制的函数,是带参数的,并且参数是对象,而不是字符串

问题补充: JS代码: <script type="text/javascript"> <!-- //--><![CDATA[//><!-- function menuFix() { var sfEls = $(".imgxia>li"); for (var i = 0; i < sfEls.length; i++) { sfEls[i].onmouseover = function() { this.className += (this.className.length > 0 ? " " : "") + "sfhover"; } sfEls[i].onMouseDown = function() { this.className += (this.className.length > 0 ? " " : "") + "sfhover"; } sfEls[i].onMouseUp = function() { this.className += (this.className.length > 0 ? " " : "") + "sfhover"; } sfEls[i].onmouseout = function() { this.className = this.className.replace(new RegExp("( ?|^)sfhover\\b"), ""); } } } window.onload = menuFix; //--><!]]> </script> css样式: <style type="text/css"> <!-- #nav { line-height: 22px; list-style-type: none; background:#666; } #nav a { display: block; text-align:center; } #nav a:link { color:#666; text-decoration:none; } #nav a:visited { color:#666;text-decoration:none; } #nav a:hover { color:#FFF;text-decoration:none;font-weight:bold; } #nav li { float: left; background:#fff; } #nav li a:hover{ background:#999; } #nav li ul { line-height: 25px; list-style-type: none;text-align:left; left: -999em; width: 90px; position: absolute; margin-top:-1px; border:solid 1px #CFCCC8; border-top:0px; padding-top:1px; background:url(../images/log/gg_1.gif) no-repeat top; } #nav li ul li{ float: left; width: 90px; background: #fff; } #nav li ul li img{ border:0px; float:left; margin-right:3px; margin-left:10px; margin-top:2px; background:none;} #nav li ul a{ wedisplay: block; width: 90p
undefined==null的主页 undefined==null | 初学一级 | 园豆:171
提问于:2010-08-27 09:22
< >
分享
最佳答案
0

var t="aaa"

setTimeout(function(){

  callme(t);

},1000);

收获园豆:20
小绿 | 菜鸟二级 |园豆:225 | 2010-08-27 09:23
其他回答(2)
0

function a() {   setTimeout(function(){alert(1)},0);   alert(2); }

jowo | 园豆:2834 (老鸟四级) | 2010-08-27 09:25
0

settimeout的函数本身是没有参数的,不过可以 利用js的闭包特性,直接使用函数外部的对象。

类似小绿提供的代码:

var t="aaa"

setTimeout(function(){

  callme(t);

},1000);

dangjian | 园豆:348 (菜鸟二级) | 2010-08-27 09:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册