如何进行 JavaScript 对象内省?
当完成探测后,据报告有效的对象对于探测到的任何属性都返回“未定义”时该怎么办? 我使用 jQuery,$('selector').mouseover(function() { });
对于函数作用域内的 $(this)
,所有内容都返回“未定义”。 选择器是地图标记的“区域”,我正在寻找其父属性。
What to do when after all probing, a reportedly valid object return 'undefined' for any attribute probed? I use jQuery, $('selector').mouseover(function() { });
Everything returns 'undefined' for $(this)
inside the function scope. The selector is a 'area' for a map tag and I'm looking for its parent attributes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的问题有点模糊,所以也许你可以提供更多细节?
至于找出一个对象及其属性的值,有很多方法可以做到这一点,包括使用 Firebug 或其他一些调试工具等。这里有一个快速但肮脏的函数,可能会帮助您开始,直到您可以提供更多详细信息:
这将显示您传递给它的对象的非
未定义
属性列表。希望有帮助...
Your question is a bit vague, so maybe you can provide more details?
As for finding out about an object and the values of its properties, there are many ways to do it, including using Firebug or some other debug tools, etc. Here is a quick and dirty function that might help get you started until you can provide more details:
That will display a list of the properties of the object that you pass it that are not
undefined
.Hope that helps...
selector
是元素的名称吗? 如果是这样,那么您应该将其引用为:否则
它将尝试查找(不存在的)“选择器”HTML 标记,但显然找不到它。
Is
selector
the name of the element? If so then you should reference it as:or
otherwise it will attempt to look for the (non-existent) "selector" HTML tag and, obviously, not find it.
虽然这个答案有点晚了,但我仍然建议查看这些链接:
http://www.webweavertech.com/ovidiu/weblog/archives/000317.html
http://www.syger.it/Tutorials/JavaScriptIntrospector.html
Though this answer is a bit late, I'd still recommend checking out these links:
http://www.webweavertech.com/ovidiu/weblog/archives/000317.html
http://www.syger.it/Tutorials/JavaScriptIntrospector.html