如何查看带有警报的对象() [英] How can I view an object with an alert()

查看:96
本文介绍了如何查看带有警报的对象()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试进行调试,但遇到了问题。现在我尝试使用 alert()。例如,我希望看到以下值:

I tried to do a debug but I am having problems. Now I try with alert(). For example I want to see the value of:

var product = { ProductName: $('!Answer_Response[0]').val(),
                  UnitPrice: $('#Price').val(),
                  Stock: $('#Stock').val()
              };

当我说 alert(产品)它只给我 [object Object] 。如何使警报显示真正存在的内容?

When I say alert(product) it just gives me [object Object]. How can I make alert show what's really there?

推荐答案

您可以使用 JSON.stringify() 在现代浏览器中找到的方法,由 json2提供。 js

you can use the JSON.stringify() method found in modern browsers and provided by json2.js.

var myObj = {"myProp":"Hello"};
alert (JSON.stringify(myObj));    // alerts {"myProp":"Hello"};

还检查此库: http://devpro.it/JSON/files/JSON-js.html

这篇关于如何查看带有警报的对象()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆