以下代码的工作示例可以在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)