jQuery单选按钮显示div [英] jQuery radio button show div

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

问题描述

嘿家伙,我可以用什么函数来说,如果这个单选按钮被选中显示这个'div'。
在此先感谢。

解决方案

HTML $ b

 < form id ='form-id'> 
< input id ='watch-me'name ='test'type ='radio'/> Show Div< br />
< input name ='test'type ='radio'/>< br />
< input name ='test'type ='radio'/>
< / form>
< div id ='show-me'style ='display:none'> Hello< / div>

jQuery
< $('#watch-me')。attr('checked'))pre> $('#form-id')。 {
$('#show-me')。show();
} else {
$('#show-me')。hide();
}
});

你可以在这里看到它: http://jsfiddle.net/wmKGd/



UPDATE 25.01.2013 <
从jQuery Library 1.8.x升级到1.9.x后 -
请使用而不是

jQuery Library 1.8.x

  jQuery('#some-id')。attr('checked')

jQuery Library 1.9.x

  jQuery('#some-id')。prop ('checked')

你可以在这里看到更新的脚本: http://jsfiddle.net/9XXRY/


Hey guys, what function could I use to say, if this radio button is checked show this 'div'. Thanks in advance.

解决方案

HTML

<form id='form-id'>
    <input id='watch-me' name='test' type='radio' /> Show Div<br />
    <input name='test' type='radio' /><br />
    <input name='test' type='radio' />
</form>
<div id='show-me' style='display:none'>Hello</div>

jQuery

$('#form-id').change(function() {
    if ($('#watch-me').attr('checked')) {
        $('#show-me').show();
    } else {
        $('#show-me').hide();
    }
});

You can see it in action here: http://jsfiddle.net/wmKGd/

UPDATE 25.01.2013
After Upgrading from jQuery Library 1.8.x to 1.9.x
Please use instead of
jQuery Library 1.8.x

jQuery('#some-id').attr('checked') 

jQuery Library 1.9.x

jQuery('#some-id').prop('checked')

You can see it with updated script in action here: http://jsfiddle.net/9XXRY/

这篇关于jQuery单选按钮显示div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆