jQuery event on change()

和自甴很熟 提交于 2019-12-02 07:11:14

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);
}); 

You can test it out here.

First of all the id on the element should be radio10 and not #radio10.

Then use this code

$("input[name='color']").change(function () {
    if ($('input#radio10').is(':checked') ) {
            $('.block-cms').show()
            }
        else {
            $('.block-cms').hide();
        }
    }); 

Here's another solution (IMO having an id on an <input type="radio"> seems a bit wrong to me):

$("input[name='color']").change(function () {
        if ($(this).val() == 1) {
            $('.block-cms').show()
            } 
        else {
            $('.block-cms').hide();
        }
    }); 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!