将 jquery 对象转储到警报框中

发布于 2024-12-23 15:35:50 字数 731 浏览 5 评论 0原文

我不太擅长操纵 jQuery,现在我需要调试一个没有文档的从我那里传下来的程序。

我有这个 var a ,一个对象,我真的很想知道它的集合的内容。在我看来,我需要 PHP 中像 foreach() 这样的函数来迭代这个对象变量。经过研究,我最终使用 jQuery.each()。现在我可以清楚地迭代并查看 var a 内部的内容。

然而,对 var a 上的每个值都发出警报有点烦人。我想知道是否可以在一次弹出的警报框中显示所有内容?

这是我的代码:

$.each(a, function(index, value) { 
alert(index + ': ' + value); 
});

var a 包含以下信息:

creationdate: date_here
id: SWFUpload
modificationdate: date_here
type: .jpg
index: 0
name: uploaded_filename.jpg
size: size_in_bytes

顺便说一句:var a 通过文件上传脚本调用。

I am not quite adept in maneuvering jQuery, and it came to a point that I need to debug a program that was passed down from me without a documentation.

I have this var a, an object, that I really want to know the content of its collection. In my mind I need a function like foreach() in PHP to iterate over this object variable. Upon researching I end up in using jQuery.each(). Now I can clearly iterate and see what was inside var a.

However, it was kind of annoying to alert once every value on the var a. What I wanna know if it's possible to display all the contents in just one pop of alert box?

Here is my code:

$.each(a, function(index, value) { 
alert(index + ': ' + value); 
});

The var a contains infos such as:

creationdate: date_here
id: SWFUpload
modificationdate: date_here
type: .jpg
index: 0
name: uploaded_filename.jpg
size: size_in_bytes

BTW: The var a is called via file upload script.

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

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

发布评论

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

评论(2

×眷恋的温暖 2024-12-30 15:35:50

为什么不将值累积到数组中,然后显示整个数组(例如,使用 JSON)?示例:

var acc = []
$.each(a, function(index, value) {
    acc.push(index + ': ' + value);
});
alert(JSON.stringify(acc));

无论如何,我建议使用 Firebug 这样的调试工具。因此,您只需使用 console.log(a) 即可在对象的字段中自由导航。

Why don't you just accumulate the values in an array, then display the whole array (for instance, using JSON)? Example:

var acc = []
$.each(a, function(index, value) {
    acc.push(index + ': ' + value);
});
alert(JSON.stringify(acc));

In any case, I'd suggest using a debug tool like Firebug. So you could just use console.log(a) and be able to navigate freely through the objects's fields.

西瓜 2024-12-30 15:35:50

在 Firefox 中你可以尝试:


alert(yourObject.toSource());

或者你可以使用一些插件:
请参阅:jQuery 转储插件

In firefox you could try:


alert(yourObject.toSource());

OR you could use some plugin:
See: jQuery Dump Plugin

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