找出是否用JQuery检查单选按钮? [英] Find out if radio button is checked with JQuery?
本文介绍了找出是否用JQuery检查单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以设置一个单选按钮来检查,但我想要做的是设置一种侦听器,当某个单选按钮被选中时激活。
以下面的代码为例:
<$单击(函数()
{
$('#radio_button')。attr(checked,checked);
} );
它增加了一个checked属性,一切都很好,但是我怎样去
添加一个警报。例如,当单选按钮被检查
而没有单击功能的帮助时弹出?
解决方案
<$ p $ ($'code> $('#element')。click(function(){
if($('#radio_button')。(':checked')){alert(checked );}
});
I can set a radio button to checked fine, but what I want to do is setup a sort of 'listener' that activates when a certain radio button is checked.
Take, for example the following code:
$("#element").click(function()
{
$('#radio_button').attr("checked", "checked");
});
it adds a checked attribute and all is well, but how would I go about adding an alert. For example, that pops up when the radio button is checked without the help of the click function?
解决方案
$('#element').click(function() {
if($('#radio_button').is(':checked')) { alert("it's checked"); }
});
这篇关于找出是否用JQuery检查单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文