jQuery事件change() [英] jQuery event on change()

查看:82
本文介绍了jQuery事件change()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表格:

    <div class="class_a">
      <fieldset>
        <label><input type="radio" id="radio10" name="color" value="1" />Red</label><br />
        <label><input type="radio" name="color" value="2" />Yellow</label><br />    
        <label><input type="radio" name="color" value="3" />Blue</label><br />
        <label><input type="radio" name="color" value="4" />Purple</label><br />
      </fieldset>
     </div>
 <div class="block-cms">
       <fieldset>
        <label><input type="radio" name="time" value="6" />12</label><br />
        <label><input type="radio" name="time" value="7" />11</label><br />    
        <label><input type="radio" name="time" value="8" />10</label><br />
        <label><input type="radio" name="time" value="9" />9</label><br />
      </fieldset>
 </div>

我在这里试图通过使用jQuery change()隐藏第二个字段集.

What im trying to do here is by using jQuery change() hide off second fieldset.

$("input#radio10").change(function () {
        var checked = true;
        checked = checked && $(this).is(':checked');
        if ($('input#radio10:checked') ) {
            $('.block-cms').show()
            } 
        else {
            $('.block-cms').hide();
        }
    }); 

不确定在这里有什么错.有人可以建议我该怎么做吗?

Not sure what con be wrong here. Can anyone suggest me what should be done different please?

推荐答案

您的id不应该具有#,用于选择器,应该只是id="radio10".

Your id shouldn't have the #, that's for the selector, it should just be id="radio10".

更改它,这就是您应该遵循的:

Change that, and this is what you should be after:

$(".class_a :radio").change(function () {
  $(".block-cms").toggle($("#radio10:checked").length > 0);
}); 

您可以在此处进行测试.

这篇关于jQuery事件change()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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