Howto validet that 2> 12表格 [英] Howto validet that 2 > 12 from a form

查看:45
本文介绍了Howto validet that 2> 12表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单中有2个输入,我想检查是否开始>结束。看起来好像

只是比较我在javascript中获得此代码时的第一个数字

" if(document.all.start> document.all.end)"

如何解决这个问题,以便比较2> 10,两个大于十,而b $ b不是,两个大于一个。

提前完成

I got 2 inputs in a form where I want check if start > end. Seems like it
just compare the first number when I got this code in javascript
"if(document.all.start > document.all.end)"
How do i solve this so it compare 2 > 10 as, is two bigger than ten, and
not, is two bigger than one.
Thanx in advance

推荐答案

在文章< 41 ******** @ news.broadpark.no> ;, ka * **** @ hotmail.com 启发我们

with ...
In article <41********@news.broadpark.no>, ka*****@hotmail.com enlightened us
with...
我在表单中输入了2个输入,我想检查是否开始>结束。好像它只是比较当我在javascript中获得此代码时的第一个数字
" if(document.all.start> document.all.end)"
我如何解决这样它比较2> 10,两个大于十,而
不是,两个大于一个。
Thanx提前
I got 2 inputs in a form where I want check if start > end. Seems like it
just compare the first number when I got this code in javascript
"if(document.all.start > document.all.end)"
How do i solve this so it compare 2 > 10 as, is two bigger than ten, and
not, is two bigger than one.
Thanx in advance




It将它们作为字符串进行比较,这就是价值总是如此。 2> 1.


使用parseInt。


远离IE专有document.all语法,即AFAIU甚至

在IE6中弃用。


if(parseInt(document.forms [" formname"]。elements [" start"]。value,10)>

parseInt(document.forms [" formname"]。elements [" end"]。value,10)>


请注意,如果值为this,则会失败不是数字(空,空白,混合等)

- 您应该在生产代码中添加一个检查。查看isNaN

函数并与NaN进行比较。


-

-

~kaeli~

针灸是一个很好的刺戳。
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace



It''s comparing them as strings, which is what the value always is. 2 > 1.

Use parseInt.

And get away from IE proprietary document.all syntax, which is AFAIU even
deprecated in IE6.

if (parseInt(document.forms["formname"].elements["start"].value,10) >
parseInt(document.forms["formname"].elements["end"].value,10) >

Note that this will fail if the value is not a number (null, blank, mix, etc)
- you should add a check for that in production code. Look at the isNaN
function and comparing to NaN.

--
--
~kaeli~
Acupuncture is a jab well done.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace


KS写道:
KS wrote:
我在表单中输入了2个输入,我想检查是否开始>结束。好像它只是比较当我在javascript中获得此代码时的第一个数字
" if(document.all.start> document.all.end)"
我如何解决这样它比较2> 10,两个大于十,而
不是,两个大于一个。
Thanx提前
I got 2 inputs in a form where I want check if start > end. Seems like it
just compare the first number when I got this code in javascript
"if(document.all.start > document.all.end)"
How do i solve this so it compare 2 > 10 as, is two bigger than ten, and
not, is two bigger than one.
Thanx in advance




< url:< a rel =nofollowhref =http://jibbering.com/faq/#FAQ4_21target =_ blank> http://jibbering.com/faq/#FAQ4_21 />


你可能想要:" if(+ a> + b)"而不是if(a> b)。请参阅上面的URL

了解更多信息。


-

Grant Wagner< gw ***** @ agricoreunited .com>

comp.lang.javascript常见问题 - http:// jibbering。 com / faq



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

You probably want: "if (+a > +b)" rather than "if (a > b)". See the URL above
for more information.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


kaeli写道:
kaeli wrote:
并远离IE专有文档。语法,即AFAIU甚至在IE6中已弃用。
And get away from IE proprietary document.all syntax, which is AFAIU even
deprecated in IE6.




我将其重新称为此新闻组中经验丰富的JavaScript作者(和

希望其他地方)建议不要使用document.all集合来

访问任何DOM元素。


这是因为不幸的是微软's文件没有显示document.all as

被弃用。


甚至更不幸的是它甚至没有显示该文件。是_not

recommended_并建议作者使用可用的DOM1方法

(getElementById(),getElementsByTagName()等)。


现在使用基于Gecko的浏览器_supporting_ document.all(除了Opera之外)

已经有一段时间了),我们不太可能在

的生命周期内看到document.all的结尾。


用一句我最喜欢的引言来解释:在2000万年的时候,当欧陆大陆漂移造成地球无法辨认,甚至连蟑螂都不能忍受

了,你可以确保使用包含document.all的脚本远离

海洋之下的Web服务器。感谢微软,Opera以及现在的支付。每次都是对Mozilla决策者的侮辱。


-

Grant Wagner< gw ***** @ agricoreunited.com>

comp.lang.javascript常见问题 - http://jibbering.com/faq



I''d re-word that as "experienced JavaScript authors in this newsgroup (and
hopefully elsewhere) recommend against using the document.all collection to
access any DOM element".

This is because unfortunately Microsoft''s document does not show document.all as
being deprecated.

What''s even more unfortunate it does not even show that document.all is _not
recommended_ and suggest authors use the available DOM1 methods
(getElementById(), getElementsByTagName(), etc) instead.

And with Gecko-based browsers now _supporting_ document.all (in addition to Opera
which has for some time), it is unlikely we will see the end of document.all in
our lifetimes.

To paraphrase a favorite quote of mine: In 20 million years when the continental
drift creates an earth unrecognizable and even cockroaches can''t stand it
anymore, you can be sure that there remain Web servers buried far beneath the
ocean with scripts containing "document.all" thanks to Microsoft, Opera and now
Mozilla (insert insult against the Mozilla decision-makers here).

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


这篇关于Howto validet that 2&gt; 12表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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