问题描述
在HTML页面上我有:
< input type =" hidden"命名= QUOT; p_row"值= QUOT 1 QUOT; />
然后在脚本中我们有:
document.forms.grid.p_row.value = document.forms.gri d。 p_row.vaue + 10;
为什么这会给我110结果?我可以看到它连接了字符串值,但我怎么告诉它将这些东西加在一起?
-
jeremy
On an HTML Page I have:
<input type="hidden" name="p_row" value="1" />
then in script we have:
document.forms.grid.p_row.value=document.forms.gri d.p_row.vaue+10;
Why does this give me 110 as the result? I can see it''s concatenating
the string values but how do I tell it to add the things together?
--
jeremy
推荐答案
< http://jibbering.com/faq/#FAQ4_21>
-
Martin Honnen
< http://jibbering.com/faq/#FAQ4_21>
<http://jibbering.com/faq/#FAQ4_21>
感谢Martin,使用其中一种方法可以正常工作 - 现在它说:
document.forms.grid.p_row.value = document.forms.gri d.p_row.value * 1 + 10;
似乎工作 - 谢谢。
-
jeremy
Thanks Martin, works OK using one of those approaches - so now it says:
document.forms.grid.p_row.value=document.forms.gri d.p_row.value*1+10;
Seems to work - thanks.
--
jeremy
输入值是字符串
转换数字
string * 1
或
+ string
和
可能
数字(字符串)
= +10 + document.forms.grid.p_row.value;
或
= document.forms.grid.p_row.value * 1 + 10;
values in inputs are strings
conversion in a number
string * 1
or
+string
and
probably
Number(string)
= +10 + document.forms.grid.p_row.value;
or
= document.forms.grid.p_row.value*1 + 10;
这篇关于连接而不是加入!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!