How to get value of selected radio button?

前端 未结 28 2738
温柔的废话
温柔的废话 2020-11-22 03:51

I want to get the selected value from a group of radio buttons.

Here\'s my HTML:

28条回答
  •  滥情空心
    2020-11-22 04:49

    The one worked for me is given below from api.jquery.com.

    HTML

    option1
    option2
    

    JavaScript

    var selectedOption = $("input:radio[name=option]:checked").val()
    

    The variable selectedOption will contain the value of the selected radio button (i.e) o1 or o2

提交回复
热议问题