JavaScript 中的匿名函数 - 浏览器依赖?

发布于 2024-11-04 02:02:38 字数 958 浏览 0 评论 0原文

我正在使用 Salesforce,我需要使用像 onfocus="js_fn1(this,'param1'..) 等的东西。

对于一个特殊的要求,我试图将一个匿名函数作为参数传递给我绑定 onfocus 的函数。这是生成的 HTML:

<input onfocus="self=this;new AutoComplete('thePage:j_id3:thePageBlockId:j_id45:j_id46:pName','thePage:j_id3:thePageBlockId:j_id45:j_id46:primaryNameSuggestWrap', searchNamesfn, function(){fireAddressSearch(self, 'thePage:j_id3:thePageBlockId:j_id45:j_id46:address', 'thePage:j_id3:thePageBlockId:j_id45:j_id46:addressSuggestWrap', searchAddressesfn, selectAddressesfn);});return false;" onkeypress="return noenter(event)" id="thePage:j_id3:thePageBlockId:j_id45:j_id46:pName" type="text" name="thePage:j_id3:thePageBlockId:j_id45:j_id46:pName" value="" class="cField" />

这在 Chrome 10 和 Firefox 3.6 中工作得很好,但它似乎在 IE8 中失败了,我已经对此进行了一些研究,但无法得出其他任何结论 - IE。在 IE8 中不支持匿名函数?

Message: Not implemented

Line: 219
Char: 1
Code: 0

在第 219 行说我有输入字段有人可以告诉我如何解决这个问题吗?

Am using Salesforce and I need to use stuff like onfocus="js_fn1(this,'param1'..) etc.

For a peculiar requirement, am trying to pass an anonymous function as a parameter to a function I am binding onfocus. Here's the generated HTML:

<input onfocus="self=this;new AutoComplete('thePage:j_id3:thePageBlockId:j_id45:j_id46:pName','thePage:j_id3:thePageBlockId:j_id45:j_id46:primaryNameSuggestWrap', searchNamesfn, function(){fireAddressSearch(self, 'thePage:j_id3:thePageBlockId:j_id45:j_id46:address', 'thePage:j_id3:thePageBlockId:j_id45:j_id46:addressSuggestWrap', searchAddressesfn, selectAddressesfn);});return false;" onkeypress="return noenter(event)" id="thePage:j_id3:thePageBlockId:j_id45:j_id46:pName" type="text" name="thePage:j_id3:thePageBlockId:j_id45:j_id46:pName" value="" class="cField" />

This works beautifully in Chrome 10 and Firefox 3.6. But it seems to fail in, you guessed it, IE8. I've had a few pokes around this but couldn't conclude anything else - that IE doesn't support anon functions in obtrusive js? IE8 said

Message: Not implemented

Line: 219
Char: 1
Code: 0

At line 219 I have the input field Can someone tell me how I can fix this?

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

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

发布评论

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

评论(1

护你周全 2024-11-11 02:02:38

感谢 meouw 的有用评论。

答: IE 中似乎保留了“self”

Thanks to meouw for the useful comment.

Answer: It seems 'self' is reserved in IE

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