连接而不是加入! [英] Concatenation instead of adition!

查看:49
本文介绍了连接而不是加入!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在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

推荐答案




Jeremy写道:



Jeremy wrote:


为什么这会给我110作为结果?我可以看到它连接了字符串值,但是我怎么告诉它将这些东西加在一起呢?
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?



< http://jibbering.com/faq/#FAQ4_21>


-


Martin Honnen
http://JavaScript.FAQTs.com/


文章< 45 *********************** @ newsspool2。 arcor-online.net>,

Martin Honnen说...
In article <45***********************@newsspool2.arcor-online.net>,
Martin Honnen says...

>


Jeremy写道:

>

Jeremy wrote:


为什么这会给我110作为结果?我可以看到它连接了字符串值,但是我怎么告诉它将这些东西加在一起呢?
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?



< 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


Jeremyaécrit:
Jeremy a écrit :

在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结果?
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?



输入值是字符串


转换数字


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;


这篇关于连接而不是加入!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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