代码之家  ›  专栏  ›  技术社区  ›  kodisha

基于select的JQuery启用按钮

  •  0
  • kodisha  · 技术社区  · 6 年前

    <script type="text/javascript" src="https://www.repfolio.com/Scripts/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="https://www.repfolio.com/Scripts/jquery.selectboxes.min.js"></script>
    <script type="text/javascript">
        $(document).ready(
            function() {
                $('.ct').bind('change', function() { updateControls(this); });
            }
        );
        function updateControls(c) {
            $('.ct').unbind();
            if ($(c).val() == 'Reset') {
                var opt = $(c).find("option[value!='Reset']");
                // if there are selects with value = '' then add this option back to them -- need to address this select too
                if ($(".ct").filter("[value='']").size() > 0) {
                    $(".ct").filter("[value='']").each(function() {
                        $(this).append($("<option></option>").attr("value", $(opt).val()).text($(opt).text()));
                    });
                    var options = $(".ct").filter("[value='']:first").children().clone();
                    $(c).find('option').remove();
                    $(c).append($(options));
                } else {
                    $(c).find('option').remove();
                    $(c).append($("<option></option>").attr("value", "").text("-- Select Column -"));
                    $(c).append($("<option></option>").attr("value", $(opt).val()).text($(opt).text()));
                };
            } else {
                var s = $(c).children().filter('option[selected=true]');
                $(c).find('option').remove();
                $(".ct option[value='" + $(s).val() + "']").each(function() { $(this).remove(); });
                $(c).append($("<option></option>").attr("value", $($(s)).val()).text($(s).text()));
                $(c).append($("<option></option>").attr("value", "Reset").text("Reset"));
            }
            $(".ct").filter("[value='']").sortOptions()
            $('.ct').bind('change', function() { updateControls(this); });
            if ($('select.ct option:nth-child(3)').length)
                $('#submit').attr('disabled', 'enabled');
        };
    </script>
    

    这是启用按钮的部分:

    if ($('select.ct option:nth-child(3)').length)
                $('#submit').attr('disabled', 'enabled');
    
    1 回复  |  直到 13 年前
        1
  •  0
  •   qlayer    12 年前
    $('#submit').attr('disabled', 'enabled');
    

    $('#submit').attr('disabled', ''); 
    

    但在这种情况下,我建议您使用“.prop”:

    $('#submit').prop('disabled', false);
    

    您可以在jQuery.api