开发者

Enabling/disabling validation controls on page load with jQuery

开发者 https://www.devze.com 2022-12-22 02:10 出处:网络
I am using jQuery to disable validation controls in an aspx page on load. On a button press I want to enable them. I have coded the script below for this, but there is an issue. Both functions (enabli

I am using jQuery to disable validation controls in an aspx page on load. On a button press I want to enable them. I have coded the script below for this, but there is an issue. Both functions (enabling and disabling validation controls) are fired on page load.

Why are both functions being called?

<script type开发者_如何学JAVA="text/javascript">

    function pageLoad() 
    {
        $.each(Page_Validators, function(index, validator) {  
           ValidatorEnable(validator, false);
        });

        $("input[id$='btnNext']").click(enable());
    } 

    function enable() 
    {
        alert ("Enable function called");
        $.each(Page_Validators, function(index, validator){
            ValidatorEnable(validator, true);
        });
    }

    </script>


Use document ready event in jQuery to disable the controls. Something like

$(function(){
    // disable controls

   $("input[id$='btnNext']").click(function(){
       enable();
   }); 
});

Edit

Replace

    $("input[id$='btnNext']").click(enable());

with

    $("input[id$='btnNext']").click(function(){
        enable();
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消