将jquery选择器中的值存储在数组或散列中以供重用
store values in a array or hash from jquery selector for reuse
如何将值存储到要单独调用的数组或散列中而不添加单独的标识符?
var myarray = [];
$(".express").each(function () {
myarray.push($(this).text());
});
function flashEXPRESS() {
$(".express").each(function () {
if ($(this).text() == 'NEW') { $(this).text() = myarray[???]; }
else { $(this).text() == 'NEW'}
});
}
var flashEXPRESSid = 0;
flashEXPRESSid = setInterval("flashEXPRESS()",1000);
对each
的回调将索引作为第一个参数。这可能就是你需要的。
$(".express").each(function (index) {
if ($(this).text() == 'NEW') { $(this).text() = myarray[index]; }
else { $(this).text() == 'NEW'}
});
从注释来看,如果您希望允许div更改和添加,而不破坏数组索引,那么像这样的东西可能会起作用:
var myarray = {}; //object, not an array
$(".express").each(function () {
var identifier = $(this).data("idforobject");
myarray[identifier] = $(this).text();
});
function flashEXPRESS() {
$(".express").each(function () {
if ($(this).text() == 'NEW') {
$(this).text() = myarray[$(this).data("idforobject")];
}
else { $(this).text() == 'NEW'}
});
}
Then on yourdiv:
<div class="express" data-idforobject="something unique">
将myarray
重命名为其他东西,因为它不再是数组
相关文章:
- 在dropdwon菜单中发出针对特定选择器jquery的问题
- 周/年选择器jQuery插件
- DOM元素的属性因选择器-jQuery而异
- 如何使用日期选择器jquery突出显示特定日期
- 如何仅使用日期选择器 Jquery 启用月份的最后几天
- 如何在日期选择器 jquery 的 Select 事件上调用 js 函数
- 如何指定多个选择器 jquery
- 在日期选择器 jQuery 中查看可用日期
- 将其与伪选择器 jquery 一起使用
- 如何将东部标准时间设置为日期选择器 (jquery ui) - 使用 javascript
- 请帮助我添加日期选择器(Jquery Ui)
- 使用缓存选择器(jQuery)选择子元素
- 选择器Jquery中的选择器
- 如何将日期选择器jquery插件添加到bootstrab
- 如何在一个选择器jQuery中显示和隐藏多个元素
- 父选择器Jquery
- 如何使用angularjs在页面加载中调用日期选择器Jquery插件
- 逆选择器jQuery
- IE中的圆角,长选择器?(jquery)
- 如何禁用和启用日期时间选择器jquery插件