当文本字段在jquery中具有相同的类名和id时,我可以从文本字段中获得最大值

can i get maximum value from text field when text field have same class name and id in jquery?

本文关键字:字段 文本 id 我可以 最大值 jquery      更新时间:2023-09-26

我想从这个文本字段中获得最大值,但是链接

html

<input class="myclass" name="foo1" id="foo1" type="text" value="57"> 
<input class="myclass" name="foo1" id="foo1" type="text" value="24"> 
<input class="myclass" name="foo1" id="foo1" type="text" value="11"> 
<input class="myclass" name="foo1" id="foo1" type="text" value="78">

js

$(".resbobot").each(function() {   
   if (parseInt($(this).val()) > parseInt($(this).val())) 
      alert ("Maximum value is"+??); 
});

可以,但是您需要将最大值存储在某个临时变量中:

var max = 0;
$( '.myclass' ).each( function() {
    if( parseInt( $( this ).val(), 10 ) > max ) {
        max = parseInt( $( this ).val(), 10 );
    }
} );
console.log( max );

jsFiddle演示