Simultaneously Iterating Over Two Sets of Elements in jQuery

前端 未结 2 1678
醉话见心
醉话见心 2021-01-22 08:17

I have a table containing many pairs of text input fields in separate columns. I want to iterate through the input fields in the first column and use those values to set the va

2条回答
  •  广开言路
    2021-01-22 09:05

    What you are wanting to do is known as a 'zip' operation. This is something seen in functional programming languages quite a lot. It is a function that combines two sequences of equal length into a single sequence containing a pair (or n-tuple) of elements.

    Here you can find an implementation of 'zip' for jquery. It's a jQuery plugin. Available on Google Code

    It looks like you can use it like tihs:

    $.zip($("input.left"), $("input.right")).each(function () {
       var left = this[0];
       var right = this[1];
    })
    

提交回复
热议问题