jQuery get specific option tag text

后端 未结 22 1654
-上瘾入骨i
-上瘾入骨i 2020-11-22 12:32

All right, say I have this:


                        
    
提交评论

  • 2020-11-22 13:19

    Try this:

    jQuery("#list option[value='2']").text()
    
    0 讨论(0)
  • 2020-11-22 13:20

    If you'd like to get the option with a value of 2, use

    $("#list option[value='2']").text();
    

    If you'd like to get whichever option is currently selected, use

    $("#list option:selected").text();
    
    0 讨论(0)
  • 2020-11-22 13:20

    Try the following:

    $("#list option[value=2]").text();
    

    The reason why your original snippet wasn't working is because your OPTION tags are children to your SELECT tag, which has the id list.

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