相关疑难解决方法(0)

如何找出jQuery中每个()的最后一个索引?

我有这样的事......

$( 'ul li' ).each( function( index ) {

  $( this ).append( ',' );

} );
Run Code Online (Sandbox Code Playgroud)

我需要知道最后一个元素的索引是什么,所以我可以这样做......

if ( index !== lastIndex ) {

  $( this ).append( ',' );

} else {

  $( this ).append( ';' );

}
Run Code Online (Sandbox Code Playgroud)

伙计们,有什么想法?

indexing each jquery loops

39
推荐指数
4
解决办法
7万
查看次数

如何确定这是否是"JQuery.each"中的最后一个迭代项

我正在使用JQuery.each迭代一些项目,但我想知道何时停止.

这是我现在的代码:

$j(".form-builder").each(function(){
  data_json+='{ "type":"'+$j(this).attr("type")+'"';
  // IF LAST ITERATION
  // data_json += '}';
  // ELSE
  //data_json+='},';
});
Run Code Online (Sandbox Code Playgroud)

我怎么能弄清楚它是否是最后一次迭代?

each jquery json

-2
推荐指数
1
解决办法
84
查看次数

标签 统计

each ×2

jquery ×2

indexing ×1

json ×1

loops ×1