Javascript 在下拉列表中更改所选文本?

Javascript 在下拉列表中更改所选文本?,javascript,jquery,drop-down-menu,Javascript,Jquery,Drop Down Menu,我想在单击按钮时更改下拉列表的选定值。类为“”的div中有几个下拉列表。其中,我想在第一个下拉列表和第二个到最后一个下拉列表中添加一个括号 该按钮调用此函数: //add parenthesis to the first child, and to the second to last child function addParens(){ var len = $(".WHERE").children('div > select').length; len

我想在单击按钮时更改下拉列表的选定值。类为“”的div中有几个下拉列表。其中,我想在第一个下拉列表和第二个到最后一个下拉列表中添加一个括号
该按钮调用此函数:

//add parenthesis to the first child, and to the second to last child
    function addParens(){
      var len = $(".WHERE").children('div > select').length;
      len -= 1;

      var firstDropdown = $('.WHERE').children().first(); //the first child
      var lastDropdown = $('.WHERE').children().eq(len);  //the second to last child
//attempting here to append left parenthesis to the first dropdown
          var text = firstDropdown.val(); //the old selected option
          text = '(' + text; //new text with left parenthesis
          console.log(text);  //prints out correctly
          firstDropdown.text(text); //tried ,doesn't work
          var firstId = firstDropdown.attr('id'); //grab id firstDropdown
          $('#'+firstId).val(text); //doesn't work by grabbing id first
          firstDropdown.val(text); //also tried this, doesn't work




    }
之后,如果我打印firstDropwdown.val(),它将打印空值,并且下拉列表没有选择任何内容。 下面是一个下拉列表的示例,它是动态创建的

函数addParens(){
var len=$(“.WHERE”).children('div>select').length;
len-=1;
var children=$('.WHERE').children();
var firstDropdown=children.first().find(“option:selected”);//第一个子项
var lastDropdown=children.eq(len).find(“option:selected”);//倒数第二个孩子
text(“(“+firstDropdown.text()+”);
lastDropdown.text(“(“+lastDropdown.text()+”)”;
}

文章作者
文章编辑
文章出版商
第条.标题
第条书名
第条.年份
文章作者
文章编辑
文章出版商
第条.标题
第条书名
第条.年份
文章作者
文章编辑
文章出版商
第条.标题
第条书名
第条.年份
文章作者
文章编辑
文章出版商
第条.标题
第条书名
第条.年份
做吧

像这样吗?对那很有效,谢谢