2016-07-11 7 views
-1

안녕하세요 여러분 cshtml에서 텍스트 상자의 색상을 변경하는 방법?. 어떻게 그것을 수행하는이 코드HTML 텍스트 상자에 조건으로 색상을 넣는 방법은 무엇입니까?

$("#BUTTON").click(function (event) { 
    var urlPA = URL; 
    var crty = $("#Courtesy").val(); 
    var fname = $("#Familyname").val(); 
    var gname = $("#GivenName").val(); 

    if (crty != 0 && fname != 0 && gname != 0) { 
     $.ajax({ 
      type: "GET", 
      url: urlPA, 

      data: 'DATA', 
      success: function (response) { 
       alert(response); 
      /// when success the color of the textbox return to normal 
      }, 
      datatype: "text" 
     }); 
    } else { alert("Please fill up the required fields."); 
    ////// when error the textbox background makes red 

} 
}); 

이? 감사.

+0

합니다. 나는 텍스트 상자가 색을 바꿀지 여부를 결정할 때 조건이 있습니다. 코드 예제를 참조하십시오. – UkI

답변

0

당신은 인라인 스타일을 설정하는 jQuery의 css 기능을 사용할 수 있습니다 @GiladGreen 그것의 다른

if (crty != 0 && fname != 0 && gname != 0) { 
    $.ajax({ 
     type: "GET", 
     url: urlPA, 

     data: 'DATA', 
     success: function (response) { 
      alert(response); 
      /// when success the color of the textbox return to normal 
      $('#Courtesy').css('background-color', 'white'); 
      // add other fields 
     }, 
     datatype: "text" 
    }); 
} else { alert("Please fill up the required fields."); 
    ////// when error the textbox background makes red 
    $('#Courtesy').css('background-color', 'red'); 
    // add other fields 
} 
+1

이 작동하지 않습니다. :( – UkI

+0

고마워요. 지금 실수를 찾아 냈습니다. – UkI