简体   繁体   English

如何使用JavaScript从下拉列表中选择一个值

[英]How to select a value from the dropdown list using javascript

I am trying to select the a value from the dropdown list from the site http://www.snapdeal.com/product/samsung-galaxy-grand-duos-i9082/638689?HID=productGrid_mobiles_1 我正在尝试从http://www.snapdeal.com/product/samsung-galaxy-grand-duos-i9082/638689?HID=productGrid_mobiles_1网站的下拉列表中选择一个值

Code used : 使用的代码:

var obj = document.getElementById('attribute-select-0'); 
    obj.options[1].selected = true;

If you manually select the from the dropdown you will see that the href and other attributes of the below div changes as you change the dropdown value 如果您从下拉菜单中手动选择,则会看到以下div的href和其他属性在更改下拉值时发生变化

console.log(document.getElementById('BuyButton-1').href);

ISSUE Yhe issue I am facing is that am selecting the dropdown value using the code that i have mentioned above but still am not getting the change expected value in the console.log(document.getElementById('BuyButton-1').href); 我面对ISSUE YHE的问题是,现在用的是我所提到的代码选择下拉值,但仍然没有我在的console.log得到变化的预期值(的document.getElementById(“BuyButton-1”)的href。);

EDIT Have also tried : 编辑也尝试过:

obj.selectedIndex = 'White';

But same result. 但结果相同。

Dont know where am i doing wrong 不知道我在哪里做错了

$("#attribute-select-0").val("White");

或使用纯Javascript:

document.getElementById("attribute-select-0").value="White";

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

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