jQuery event on change()

后端 未结 3 1335
离开以前
离开以前 2021-01-25 12:42

I have a simple form:

    
相关标签:
3条回答
  • 2021-01-25 12:50

    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();
            }
        }); 
    
    0 讨论(0)
  • 2021-01-25 12:56

    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.

    0 讨论(0)
  • 2021-01-25 13:04

    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();
            }
        }); 
    
    0 讨论(0)
提交回复
热议问题