将元素存储在数组中,然后在jquery中使用它 [英] Store elements inside an array then use it later in jquery

查看:113
本文介绍了将元素存储在数组中,然后在jquery中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var els = []; 
els.push($(#something));

我需要将它添加到数组中,因为#something的属性将被更改,我需要得到它的原始属性(高度,宽度位置等)。



我现在如何使用els数组中的元素?

  $ something = $('#something'); 
els [$ something.attr('id')] = {
width:$ something.width(),
height:$ something.height(),
offset: $ something.offset()};

console.log(els ['something']);


var els = [];
els.push($("#something"));

I need to add this to the array because the properties of #something will be changed and I need to get it's original properties (height,width position etc.)

how do I now use the element inside els array?

解决方案

I would not store the entire object if there are only a few properties required.

$something = $('#something');
els[$something.attr('id')] = { 
  width: $something.width(),
  height: $something.height(),
  offset: $something.offset() };

console.log(els['something']);

这篇关于将元素存储在数组中,然后在jquery中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆