Home>Article>Web Front-end> How to determine whether the radio button radio is selected in jquery

How to determine whether the radio button radio is selected in jquery

coldplay.xixi
coldplay.xixi Original
2020-11-25 16:02:57 2104browse

Jquery method to determine whether the radio button radio is selected: 1. Get the id when loading the page, the code is [var fs=$("#" id).val()]; 2. Click the button When getting the id, the code is [var id= $(this).attr("id")].

How to determine whether the radio button radio is selected in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.

How jquery determines whether the radio button radio is selected:

The example in this article describes how jquery determines whether the radio button radio is selected. Share it with everyone for your reference. The details are as follows:

html code is as follows:

  

1. Get the id

$("input[type='radio']").each(function(){ var id= $(this).attr("id"); if($("#"+id).attr("checked")=="checked"){ var fs=$("#"+id).val(); } }); var s1 = $(".aa:checked").val(); // .aa 为class var s2 = $("input[name='ra']:checked").val();

when loading the page 2. Get the id

$(function(){ $("input[type='radio']").click(function(){ var id= $(this).attr("id"); alert(id); }); });
when you click the button

Related free learning recommendations:javascript(video)

The above is the detailed content of How to determine whether the radio button radio is selected in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn