是否有一个JavaScript相当于Java的deepToString()的? [英] Is there a JavaScript equivalent of Java's deepToString()?
问题描述
我正在调试的一些javascript,并保持运行到一个javascript [对象]
(例如,whenI显示与值的警报,它dsplays为 [对象]
或 NaN的
)。我试图读取该对象的内容。我知道在Java中,这将是 deepToString()一个完美的工作;
是否有任何JavaScript等同于法
I'm working on debugging some javascript, and keep running into a javascript [object]
(e.g., whenI display an alert with the value, it dsplays as [object]
or NaN
). I'm trying to read the contents of this object. I know in Java, this would be a perfect job for deepToString();
Is there any javascript equivalent to that method?
这里的code产生上述目的...
Here's the code generating the aforementioned object...
e = document.getElementById("contServer"); // contServer is an integer variable
var valueCS = parseInt(e.options[e.selectedIndex].value);
//Value CS is a four-byte variable calculated from e
为JavaScript的方式去code'的这个对象变量,所以我可以看看有什么的真正的内部的任何想法?
感谢
推荐答案
确定这样看着你原来的HTML code后
ok so after looking at your original html code
<select id="contServer" name="contServer">
<option valueCS=1000>Up</option>
<option valueCS=0>Down</option>
</select>
这是无效的HTML,下面是一个选项应该怎么看起来像
this is invalid html, below is how an option should look like
<option selected="selected" value="1000">Up</option>
如果你做同样的code这将返回1000,这是value属性。
if you do the same code this will return 1000, which is the value attribute
如果您有类似下面的
<option selected="selected" value="0">1000</option>
您code将返回0,因为值设置为0,这应该让你对你的方式来纠正我们的code
your code will return 0, because value is set to 0. This should get you on your way to correct our code
这篇关于是否有一个JavaScript相当于Java的deepToString()的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!