获得最大的身份证

Jam*_*mes 3 jquery

任何人都可以为我提供解决方案.问题是我在一个带有jquery的html页面中动态生成thd id.我想找到最大的Id,如果id是例如:id0,id1,id2 ..........任何人都给我一个解决方案.谢谢你的阅读.

Gab*_*oli 5

以下代码的工作示例可以在http://www.jsfiddle.net/LdgN9/2/找到

// create an array
var ar = new Array();
// for each element with id that starts with 'id'
$('[id^="id"]').each(
     function(){
                // add it to the array (only its numeric part)
                ar.push(
                        // extract the numeric part to be added in the array
                        parseInt( $(this).attr('id').replace('id','') )
                      );
               });
// find the max value in the array 
alert('id' + Math.max.apply( Math, ar ));
Run Code Online (Sandbox Code Playgroud)