Javascript 访问jquery each()迭代器函数中的JS对象

Javascript 访问jquery each()迭代器函数中的JS对象,javascript,jquery,javascript-objects,Javascript,Jquery,Javascript Objects,如何访问在上一次迭代中设置的框的值?或者,是否可以通过某种密钥访问它 $('input.ISSelectSearch').each(function(i) { var box = new Object; box.size = 80; box.width = 110; //CODE CODE CODE }); 问题是,我需要知道与每个'input.ISSelectSearch'元素框关联的数据,以便根据当前或之前的框对象的值更改它们。换句话说,我需要元素框对象之间

如何访问在上一次迭代中设置的
框的值?或者,是否可以通过某种密钥访问它

$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    //CODE CODE CODE
});

问题是,我需要知道与每个
'input.ISSelectSearch'
元素框关联的数据,以便根据当前或之前的框对象的值更改它们。换句话说,我需要元素框对象之间的连接,这样我就可以根据另一个对象的值指定其中的某些更改。

您可以这样做

$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    prevsize = $(this).box[/* previous iteration element id or name */].size
    //CODE CODE CODE
}); 
在注释后编辑:-
可能您想使用$.data()方法
这是因为您可以将数据与元素关联
所以在循环中你可以

var pre = null;
$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    //condition so that first time it dosent shows an error
    if(pre!=null){
     //CODE

    }
    pre = this;
    //CODE CODE CODE
}); 

你可以这样做

$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    prevsize = $(this).box[/* previous iteration element id or name */].size
    //CODE CODE CODE
}); 
在注释后编辑:-
可能您想使用$.data()方法
这是因为您可以将数据与元素关联
所以在循环中你可以

var pre = null;
$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    //condition so that first time it dosent shows an error
    if(pre!=null){
     //CODE

    }
    pre = this;
    //CODE CODE CODE
}); 

如果你喜欢,你可以用索引来做

$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    $('input.ISSelectSearch').data(i,box);
    //and now you can retrive the data whenevr you want
    var olderObject = $('input.ISSelectSearch').data(SOME_OLDER_INDEX)
});

如果你喜欢,你可以用索引来做

$('input.ISSelectSearch').each(function(i) {
    var box = new Object;
    box.size = 80;
    box.width = 110;
    $('input.ISSelectSearch').data(i,box);
    //and now you can retrive the data whenevr you want
    var olderObject = $('input.ISSelectSearch').data(SOME_OLDER_INDEX)
});

您确定要先满足条件吗=无效的在哪个迭代中它不为空?我想您希望
pre=this
在ifOk之外,如果每个循环中有5个元素,例如,我需要从第3个元素访问1fst元素框对象属性。我不想使用任何全局变量,比如pre。也许有一些操作方法可以访问内存中存储的所有box对象。我认为JS和jquery以某种方式将它们存储到内存或etc共享存储中。您确定要预先设置条件吗=无效的在哪个迭代中它不为空?我想您希望
pre=this
在ifOk之外,如果每个循环中有5个元素,例如,我需要从第3个元素访问1fst元素框对象属性。我不想使用任何全局变量,比如pre。也许有一些操作方法可以访问内存中存储的所有box对象。我认为JS和jquery以某种方式将它们存储到内存或etc共享存储中