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

前端 未结 22 1322
夕颜
夕颜 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:34

    If you are trying to bind select with ID then the following code worked for me.

    
    

    AND THIS IS TEH JS CODE

    $( document ).ready(function() {
          var text = "EMCV IRES Puromycin Expression Plasmid - pSF-CMV-EMCV-Puro  > £114.00";
          alert(text);
    $("#groupsel_0 option").filter(function() {
      //may want to use $.trim in here
      return $(this).text() == text;
    }).prop('selected', true);
    });
    

提交回复
热议问题