【问题标题】:How to select a value from the dropdown list using javascript如何使用javascript从下拉列表中选择一个值
【发布时间】:2015-10-14 07:34:00
【问题描述】:

我正在尝试从网站http://www.snapdeal.com/product/samsung-galaxy-grand-duos-i9082/638689?HID=productGrid_mobiles_1 的下拉列表中选择一个值

使用的代码:

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

如果您从下拉列表中手动选择,您将看到下面 div 的 href 和其他属性会随着您更改下拉列表值而发生变化

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

ISSUE 我面临的问题是我使用上面提到的代码选择下拉值,但仍然没有在 console.log(document.getElementById( 'BuyButton-1').href);

编辑也试过了:

obj.selectedIndex = 'White';

但结果相同。

不知道我哪里做错了

【问题讨论】:

    标签: javascript drop-down-menu


    【解决方案1】:
    $("#attribute-select-0").val("White");
    

    或使用纯 Javascript:

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

    【讨论】:

    • 它也会导致与问题中提到的相同的问题
    • 快速浏览 fiddler 说发生了一些 ajax 调用,但无法确定执行魔术的确切脚本。但是想知道在 snapdeal 页面上做这个练习的需要是什么!
    • 基本上我想点击立即购买按钮并将产品添加到购物车。但“立即购买”按钮仅在您选择产品颜色时才有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    相关资源
    最近更新 更多