jQuery - setting the selected value of a select control via its text description

前端 未结 22 1470
夕颜
夕颜 2020-11-22 09:16

I have a select control, and in a javascript variable I have a text string.

Using jQuery I want to set the selected element of the select control to be the item with

22条回答
  •  礼貌的吻别
    2020-11-22 09:36

     $('#theYear').on('change', function () {
     FY = $(this).find('option:selected').text();
     $('#theFolders').each(function () {
         $('option:not(:contains(' + FY + '))', this).hide();
     });
     $('#theFolders').val(0);
    });
    
    $('#theYear').on('mousedown', function () {
     $('#theFolders option').show().find('option:contains("Select")', this).attr('selected', 'selected');
    });
    

提交回复
热议问题