Use JQuery to check a checkbox in a parent list-item?

后端 未结 4 1037
刺人心
刺人心 2021-01-13 09:41

I\'m brand new to Javascript and JQuery, so I\'ve been reading up on it and am trying to check (and set inactive) a checkbox in a parent list-item when one of the children a

4条回答
  •  佛祖请我去吃肉
    2021-01-13 09:42

    Based on your posted markup, this will work:

    $('ul > li ul li > :checkbox').change(function() {
        $(this).parents('li:last')
               .children("input")
               .attr("disabled", this.checked);
    });
    

    Also note:

    • You have numeric and duplicate IDs, which are invalid.
    • You do not have any class named 'child' in your document.
    • .toggle "displays or hides matched elements". It does not toggle their 'disabled' property.

    Try it here: http://jsfiddle.net/karim79/QfTfr/

提交回复
热议问题