我有關於jQuery的問題。我有下面的代碼工作正常;它根據其輸入和輸入的值更改input
border-color
。但如果在input
的頁面加載值不會改變border-color
。如何在頁面加載之後從頭開始更改border-color
?如何改變輸入邊框顏色,與jQuery,取決於它的價值?
謝謝:)
<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");
}
});
出色答卷! – Yeronimo