2014-02-27 47 views
0

我有使用javascript驗證我的表單。我想設置ErrorControl css代碼。但我無法獲得輸出。通過javascript在asp.net textbox控件中設置css類

<style type="text/css"> 
    .ErrorControl 
    { 
     background-color: #FBE3E4; 
     border: solid 1px Red; 
    } 
</style> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     //HighlightControlToValidate(); 
     $("#Button1").click(function() { 
      if (typeof (Page_Validators) != "undefined") { 
       for (var i = 0; i < Page_Validators.length; i++) { 
        if (!Page_Validators[i].isvalid) { 
         $('#' + Page_Validators[i].controltovalidate).className = "ErrorControl"; 
        } 
        else { 
         $('#' + Page_Validators[i].controltovalidate).css("border", "solid 1px White"); 
        } 
       } 
      } 
     }); 
    }); 
</script> 
+0

什麼是在控制檯中顯示? – tnanoba

回答

1

試試這個

<script type="text/javascript"> 
$(document).ready(function() { 
    //HighlightControlToValidate(); 
    $("#Button1").click(function() { 
     if (typeof (Page_Validators) != "undefined") { 
      for (var i = 0; i < Page_Validators.length; i++) { 
       if (!Page_Validators[i].isvalid) { 
        $('#' + Page_Validators[i].controltovalidate).addClass("ErrorControl"); 
       } 
       else { 
        $('#' + Page_Validators[i].controltovalidate).css("border", "solid 1px White"); 
       } 
      } 
     } 
    }); 
}); 

1

嘗試改變

$('#' + Page_Validators[i].controltovalidate).className = "ErrorControl"; 

$('#' + Page_Validators[i].controltovalidate).addClass("ErrorControl"); 
相關問題