如何使用jQuery在表中选择第n个下拉列表?

时间:2013-04-14 09:34:03

标签: jquery asp.net-mvc-3

我正在使用带有IE10的JQuery 1.8.11版本。

我有一个单行的表。表格ID为#listTable<tr> ID为#listTableRow<td> ID为#days

该行有多个单元格,每个单元格中都有一个具有相同ID的下拉列表:#searchString。我希望能够在第三个单元格中选择下拉列表,并将其选项设置为option:first。我已经能够使用下面的代码选择td,但不能选择特定的下拉列表。如何在表格中选择第3个下拉列表?

<script type="text/javascript">

  $(document).ready(function () {
    var nos = $('#listTable #searchString').length;

    $.each($checkboxes, function () {
      if ($(this).is(':checked')) {
        $('#listTable #days:nth-child(3)').css('border', '2px dashed blue');             
    });

  });                 
</script>

1 个答案:

答案 0 :(得分:1)

这将选择第三个单元格中的下拉列表,并将其选项设置为选项:first

$('#listTable td').eq(2).find("#searchString option:first").prop('selected', true);
相关问题