大家好,我正在尝试更改一个下拉列表选择的索引,一旦另一个更改,我想使用 jquery 来选择下拉列表。这是我的一些代码:
<div id = "monthlist">
<select name = "months">
<option value = 1 > January </option>
<option value = 2 > Febuary </option>
<option value = 3 > March </option>
<option value = 4 > April </option>
<option value = 5 > May </option>
<option value = 6 > June </option>
<option value = 7 > July </option>
<option value = 8 > August </option>
<option value = 9 > September </option>
<option value = 10 > October</option>
<option value = 11 > November </option>
<option value = 12 > December </option>
</select>
</div>
<div id = "yearlist">
<select name = "years">
<option value = 1993 > 1993 </option>
<option value = 1994 > 1994 </option>
<option value = 1995 > 1995 </option>
<option value = 1996 > 1996 </option>
<option value = 1997 > 1997 </option>
<option value = 1998 > 1998 </option>
<option value = 1999 > 1999 </option>
<option value = 2000 > 2000 </option>
<option value = 2001 > 2001 </option>
</select>
</div>
JQuery 代码在这里:
$("#monthlist").change(function(){
$("select#yearlist").prop('selectedIndex', 2);
});
一旦更改了月列表下拉列表,我想将“年列表”的选定索引设置为特定索引。但是我的选择器或我的代码不正确,任何建议或提示将不胜感激。