使用jquery重新选择所选的下拉框项目

时间:2012-01-05 06:48:04

标签: javascript jquery drop-down-menu

我在页面上有一个下拉框,表示该页面上的文章所在的区域。通过下拉框中的选择,该区域处于活动状态。

我想要的是可以在该页面上再次选择该项目。我想看到这发生在jquery上。

你知道怎么做吗?

1 个答案:

答案 0 :(得分:0)

您可以通过执行以下操作之一在select元素中设置项目:

$('#article')[0].selectedIndex = 3;
$('#article').attr('selectedIndex', 3);
$('#article').prop('selectedIndex', 3);

取决于您正在使用的jQuery版本。

如果你想操作值而不是索引,你可以这样做:

// sets selected index of a select box to the option with the value "0"
$("#article").val('0'); 

// sets selected index of a select box to the option with the value ""
$("#article").val(''); 
相关问题