JavaScript 中的匿名函数 - 浏览器依赖?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 meouw 的有用评论。
答: IE 中似乎保留了“self”
Thanks to meouw for the useful comment.
Answer: It seems 'self' is reserved in IE