Home > Web Front-end > JS Tutorial > body text

jquery判断单选按钮radio是否选中的方法_jquery

WBOY
Release: 2016-05-16 16:01:00
Original
1156 people have browsed it

本文实例讲述了jquery判断单选按钮radio是否选中的方法。分享给大家供大家参考。具体如下:

html代码如下:



Copy after login

1. 加载页面的时候获取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();
Copy after login

2.点击按钮的时候获取id

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

希望本文所述对大家的jQuery程序设计有所帮助。

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 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!