javascript - 获取动态添加选项的选项值
问题描述
这里是为选择标签创建选项的代码,我想要更改选项时的选项值,我已经尝试了几乎所有可以放入其中的东西,但没有运气,我什至看不到选项中的“选定”属性,我添加了html结构和代码的图片。请分享您对此的看法。谢谢。这是小提琴 - https://jsfiddle.net/pa8e47nx/1/
Product.Config.prototype.loadOptions = function() {
this.settings.each(function(element){
element.disabled = false;
element.options[0] = new Option(this.config.chooseText, '');
var attributeId = element.id.replace(/[a-z]*/, '');
var options = this.getAttributeOptions(attributeId);
if(options) {
var index = 1;
for(var i=0;i<options.length;i++){
options[i].allowedProducts = options[i].products.clone();
element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
if (typeof options[i].price != 'undefined') {
element.options[index].setAttribute('price', options[i].price);
}
element.options[index].setAttribute('data-label', options[i].label.toLowerCase());
element.options[index].config = options[i];
index++;
}
}
this.reloadOptionLabels(element);
}.bind(this));
},
解决方案
推荐阅读
- javascript - 在 node.js 中一次读取一个 html 文件
- c# - 关闭窗口后的TaskCanceledException
- javascript - 下载图像时的加载器
- mysql - MySQL,其中列包含另一列的字符串的一部分
- java - Vim-YouCompleteMe-Java:跳转到依赖项中的声明
- javascript - 我无法访问另一个文件中的函数
- c# - 通过 VPN 连接访问公司专用网络上的远程网站
- react-native - React Native 从堆栈导航器中隐藏顶部导航
- mysql - 如何将表与行值的条件连接起来?
- python - 跳过 NaN 值以获取距离