繁体   English   中英

jQuery-如何从元素值创建数组?

[英]jquery - How can I create an array from element values?

我需要创建一个数组来关联两组元素中的值。 因此,当我调用第一个时,我得到了相关值。 这是我尝试过的方法,但是没有用。 你能指出我正确的方向吗?

var key1 = jQuery('#edit-line-item-fields-field-select-zone-und option[value="1"]').text();
var price = {
key1 : jQuery('.field-name-field-price-1-zona .field-item').text()
};
console.log(price.key1);

您需要使用方括号表示法:

const key = "whatever", value = "value";
const price = {
  [key]: value
};
console.log(price[key]);

price.key访问pricekey属性。 price[key]访问key字符串标识的属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM