How to determine whether a radio button is selected in jquery

coldplay.xixi
Release: 2023-01-04 09:36:27
Original
4808 people have browsed it

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

How to determine whether a radio button is selected in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer. This method is suitable for all brands of computers.

Jquery method to determine whether a radio button is selected:

The html code is as follows:

  
Copy after login

1. Get the id

when loading the page
$("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();
Copy after login

2. Get the id when clicking the button

$(function(){ $("input[type='radio']").click(function(){ var id= $(this).attr("id"); alert(id); }); });
Copy after login

Related learning recommendations:javascript learning tutorial

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!