创建动态变量和JS 中的函数

发布于 2024-11-17 00:14:23 字数 760 浏览 3 评论 0原文

我对 JS 相当陌生,但熟悉 AS2(Flash)。在Flash中,我可以将变量放入movieclips(对象)中,并尝试使用下拉菜单执行类似的操作:

http://tamalecreative.com.au/korban/scripts/dropdown.js

具体来说:

   function dropOpen() {
       dropClose(this)
       this.overTrue = true;
       console.log(this.overTrue);
       myNum = 0;
       this.liLength = ($(this).find('ul').children().length)+1;
       for (i=0;i<=this.liLength;i++) {
           this.animateTimer = window.setTimeout(animateIn, (80 * i), this);
       }
   };

我的问题是“this.overTrue”布尔变量。它似乎适用于除 IE 之外的所有版本。我收到错误消息,对象“overTrue”不存在。这对我来说是有意义的,因为我从未声明过。有没有办法让我在“this”内声明变量“overTrue”?还是我以完全错误的方式处理这个问题?

提前致谢

I'm fairly new to JS but am familiar with AS2(Flash). In Flash I can put variables inside movieclips (objects) and have attempted to do something similar here with dropdowns:

http://tamalecreative.com.au/korban/scripts/dropdown.js

specifically:

   function dropOpen() {
       dropClose(this)
       this.overTrue = true;
       console.log(this.overTrue);
       myNum = 0;
       this.liLength = ($(this).find('ul').children().length)+1;
       for (i=0;i<=this.liLength;i++) {
           this.animateTimer = window.setTimeout(animateIn, (80 * i), this);
       }
   };

My problem is with the 'this.overTrue' boolean variable. It seems to work in everything but IE. I get the error that the object 'overTrue' doesn't exist. Which kind of makes sense to me since I never declared it. Is there a way for me to declare the var 'overTrue' inside 'this'? Or am I going about this the completely wrong way?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2024-11-24 00:14:23

看起来 IE 搞砸了最后一个参数,一个可能的解决方法可能是:

var that = this;
this.animateTimer = window.setTimeout(function() {
  animateIn(that);
}, (80 * i));

在每个“正常”浏览器中,setTimeout 签名是这样的:

window.setTimeout(func, delay, [param1, param2, ...]);

在 IE 然而 中,签名是稍微不同

window.setTimeout(vCode, iMilliSeconds [, sLanguage])

Bravo IE。你又给了我一个惊喜

Seems like IE is screwing up with the last parameter, a possible workaround might be:

var that = this;
this.animateTimer = window.setTimeout(function() {
  animateIn(that);
}, (80 * i));

In every 'sane' browser, setTimeout signature is like this:

window.setTimeout(func, delay, [param1, param2, ...]);

In IE however the signature is slightly different:

window.setTimeout(vCode, iMilliSeconds [, sLanguage])

Bravo IE. You've surprised me one more time

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文