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();
});
精彩评论