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");
}
});