jquery method to determine whether radio button radio is selected

  • 2020-06-07 03:56:49
  • OfStack

This article illustrates how jquery determines whether radio button radio is selected. Share to everybody for everybody reference. The details are as follows:

The html code is as follows:

<input type="radio" id="d1" name="ra" value="a" checked="checked" />
<input type="radio" id="d2" name="ra" value="b" />
<input type="radio" id="d3" name="ra" value="c" />

1. Get id when the page loads

  var id= $(this).attr("id");
   var fs=$("#"+id).val();
var s1 = $(".aa:checked").val(); // .aa  for class
var s2 = $("input[name='ra']:checked").val();

2. Get id when you click the button

    var id= $(this).attr("id");

I hope this article has been helpful for your jQuery programming.

Related articles: