单选按钮检查事件处理

单选按钮检查事件处理

本文介绍了单选按钮检查事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

In my application, I need a radio group, in which whenever a radio-button is checked, an alert occur so that I can post it's value to ajax post with jQuery.

In my application, I need a radio group, in which whenever a radio-button is checked, an alert occur so that I can post it's value to ajax post with jQuery.

你能帮我吗,请问我如何在 jQuery 中做到这一点?

Can you help me please how i can do it in jQuery?

推荐答案

试试这样的:

$(function(){
  $('input[type="radio"]').click(function(){
    if ($(this).is(':checked'))
    {
      alert($(this).val());
    }
  });
});

如果你给你的单选按钮一个类,那么你可以用 $('.someclass') 替换代码 $('input[type="radio"]')代码>.

If you give your radio buttons a class then you can replace the code $('input[type="radio"]') with $('.someclass').

这篇关于单选按钮检查事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 16:58