将 jquery 对象转储到警报框中
我不太擅长操纵 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不将值累积到数组中,然后显示整个数组(例如,使用 JSON)?示例:
无论如何,我建议使用 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:
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.
在 Firefox 中你可以尝试:
或者你可以使用一些插件:
请参阅:jQuery 转储插件
In firefox you could try:
OR you could use some plugin:
See: jQuery Dump Plugin