select an option with partial matching in option value

后端 未结 4 1656
生来不讨喜
生来不讨喜 2020-12-22 01:36

my dropdown is like


                        
    
提交评论

  • 2020-12-22 01:45

    you can do like this:

    $("#taskType option").each(function(){
    
        if($(this).val().indexOf(":4") != -1)
        {
            $(this).prop("selected", true)
        }
    
    });
    

    FIDDLE DEMO

    0 讨论(0)
  • 2020-12-22 01:55

    Try This

    $("#taskType option[value~=':4']").prop("selected", true);
    
    0 讨论(0)
  • 2020-12-22 02:03

    You can use attribute ends with selector

    $("#taskType option[value$=':4']").prop("selected", true);
    

    Demo: Fiddle

    0 讨论(0)
  • 提交回复
    热议问题