Javascript 如何设置下拉数组的值

Javascript 如何设置下拉数组的值,javascript,jquery,Javascript,Jquery,我在这里有这样的想法 <select id="brands[]" name="brands[]"><option value="121">...</option>...</select> <select id="brands[]" name="brands[]"><option value="122">...</option>...</select> <select id="brands[]"

我在这里有这样的想法

<select id="brands[]" name="brands[]"><option value="121">...</option>...</select>
<select id="brands[]" name="brands[]"><option value="122">...</option>...</select>
<select id="brands[]" name="brands[]"><option value="123">...</option>...</select>
<select id="brands[]" name="brands[]"><option value="124">...</option>...</select>
 ...
这是行不通的。是否有男孩知道我如何通过dropdownbox品牌编号x的值更改所选项目


我不知道ID必须是唯一的

但是,您可以使用
name

var selects = $('select[name="brands[]"]')
selects.eq(0).val('121'); 
selects.eq(1).val('122');   
selects.eq(2).val('123'); 
selects.eq(3).val('124'); 

ID必须是唯一的。不能有多个ID相同的元素。请添加一个类,或使用
name
属性进行选择。另外,
$(“#brands”)[0]
不会返回jQuery对象。为什么有多个选择?似乎您希望只有一个下拉列表。谢谢您的提示。我给了每个盒子一个自己的id。现在我可以通过它的id来更改值。这很好。非常感谢
var selects = $('select[name="brands[]"]')
selects.eq(0).val('121'); 
selects.eq(1).val('122');   
selects.eq(2).val('123'); 
selects.eq(3).val('124');