如何进行 JavaScript 对象内省?

发布于 2024-07-09 17:43:59 字数 184 浏览 7 评论 0原文

当完成探测后,据报告有效的对象对于探测到的任何属性都返回“未定义”时该怎么办? 我使用 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 技术交流群。

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

发布评论

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

评论(3

冷心人i 2024-07-16 17:43:59

你的问题有点模糊,所以也许你可以提供更多细节?

至于找出一个对象及其属性的值,有很多方法可以做到这一点,包括使用 Firebug 或其他一些调试工具等。这里有一个快速但肮脏的函数,可能会帮助您开始,直到您可以提供更多详细信息:

function listProperties(obj) {
   var propList = "";
   for(var propName in obj) {
      if(typeof(obj[propName]) != "undefined") {
         propList += (propName + ", ");
      }
   }
   alert(propList);
}

这将显示您传递给它的对象的非未定义属性列表。

希望有帮助...

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:

function listProperties(obj) {
   var propList = "";
   for(var propName in obj) {
      if(typeof(obj[propName]) != "undefined") {
         propList += (propName + ", ");
      }
   }
   alert(propList);
}

That will display a list of the properties of the object that you pass it that are not undefined.

Hope that helps...

絕版丫頭 2024-07-16 17:43:59

selector 是元素的名称吗? 如果是这样,那么您应该将其引用为:

$('area#selector')

否则

$('#selector')

它将尝试查找(不存在的)“选择器”HTML 标记,但显然找不到它。

Is selector the name of the element? If so then you should reference it as:

$('area#selector')

or

$('#selector')

otherwise it will attempt to look for the (non-existent) "selector" HTML tag and, obviously, not find it.

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