How to get all child inputs of a div element (jQuery)

前端 未结 6 1759
一生所求
一生所求 2020-12-12 11:52

HTML:

6条回答
  •  不知归路
    2020-12-12 12:38

    If you are using a framework like Ruby on Rails or Spring MVC you may need to use divs with square braces or other chars, that are not allowed you can use document.getElementById and this solution still works if you have multiple inputs with the same type.

    var div = document.getElementById(divID);
    $(div).find('input:text, input:password, input:file, select, textarea')
            .each(function() {
                $(this).val('');
            });
    $(div).find('input:radio, input:checkbox').each(function() {
        $(this).removeAttr('checked');
        $(this).removeAttr('selected');
    });
    

    This examples shows how to clear the inputs, for you example you'll need to change it.

提交回复
热议问题