2016-07-11 3 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

@GiladGreen Его другое. У меня есть условие, если текстовое поле изменит цвет или нет. См. Пример кода. – UkI

ответ

0

Вы можете использовать css функцию JQuery, чтобы установить встроенный стиль:

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

Смежные вопросы