我对 jQuery 有疑问。我有下面的代码可以正常工作;它input
border-color
根据键入和输入的值而变化。但是,如果在input
页面加载时 in 的值不会改变border-color
. border-color
在页面加载之后,如何从头开始进行更改?
谢谢 :)
<input type="text" class="col" value="">
// When the <input>'s value changes
$("input").change(function() {
// If the value is less than 7, add a red border
if ($(this).val() < 7) {
$(this).css("border", "5px solid red");
}
// Else if the value is equal to 7, add a green border
else if ($(this).val() == 7) {
$(this).css("border", "5px solid green");
}
// Else if the value is greater than 7, add an orange border
else if ($(this).val() > 7) {
$(this).css("border", "5px solid orange");
}
// Else if the value is anything else, add a black border
else {
$(this).css("border", "5px solid black");
}
});