如何在有条件的 html 文本框中添加颜色?
How to put a color in html textbox with a condition?
大家好,如何在 cshtml 中更改文本框的颜色?。我有这个代码
$("#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
}
});
怎么做?。谢谢
您可以使用jQuery的css
函数来设置内联样式:
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
}
大家好,如何在 cshtml 中更改文本框的颜色?。我有这个代码
$("#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
}
});
怎么做?。谢谢
您可以使用jQuery的css
函数来设置内联样式:
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
}