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

How to determine whether a radio button is selected in jquery

藏色散人
藏色散人 Original
2021-01-27 09:17:17 2768browse

The jquery method to determine whether a radio button is selected: First, when loading the page, obtain the id through "$(this).attr("id");"; then obtain the id when the button is clicked and Just make the judgment.

How to determine whether a radio button is selected in jquery

The operating environment of this tutorial: windows7 system, jquery1.2.6 version, DELL G3 computer.

Recommended:jquery video tutorial

Jquery method to determine whether the radio button radio is selected

The html code is as follows:

  

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();

2. Get the id

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

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!

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