disable all form elements inside div

后端 未结 12 1765
栀梦
栀梦 2020-12-04 08:39

is there a way to disable all fields (textarea/textfield/option/input/checkbox/submit etc) in a form by telling only the parent div name in jquery/javascript?

相关标签:
12条回答
  • 2020-12-04 08:58

    Try using the :input selector, along with a parent selector:

    $("#parent-selector :input").attr("disabled", true);
    
    0 讨论(0)
  • 2020-12-04 09:00

    Only text type

    $(".form-edit-account :input[type=text]").attr("disabled", "disabled");
    

    Only Password type

    $(".form-edit-account :input[type=password]").attr("disabled", "disabled");
    

    Only Email Type

    $(".form-edit-account :input[type=email]").attr("disabled", "disabled");
    
    0 讨论(0)
  • 2020-12-04 09:01
        $(document).ready(function () {
            $('#chkDisableEnableElements').change(function () {
                if ($('#chkDisableEnableElements').is(':checked')) {
                    enableElements($('#divDifferentElements').children());
                }
                else {
                    disableElements($('#divDifferentElements').children());
                }
            });
        });
    
        function disableElements(el) {
            for (var i = 0; i < el.length; i++) {
                el[i].disabled = true;
    
                disableElements(el[i].children);
            }
        }
    
        function enableElements(el) {
            for (var i = 0; i < el.length; i++) {
                el[i].disabled = false;
    
                enableElements(el[i].children);
            }
        }
    
    0 讨论(0)
  • 2020-12-04 09:02
    $('#mydiv').find('input, textarea, button, select').attr('disabled','disabled');
    
    0 讨论(0)
  • 2020-12-04 09:07

    Simply this line of code will disable all input elements

    $('#yourdiv *').prop('disabled', true);
    
    0 讨论(0)
  • 2020-12-04 09:08

    Use the CSS Class to prevent from Editing the Div Elements

    CSS:

    .divoverlay
    {
    position:absolute;
    width:100%;
    height:100%;
    background-color:transparent;
    z-index:1;
    top:0;
    }
    

    JS:

    $('#divName').append('<div class=divoverlay></div>');
    

    Or add the class name in HTML Tag. It will prevent from editing the Div Elements.

    0 讨论(0)
提交回复
热议问题