我希望Input和Textarea在值爲空時通過JavaScript變成紅色,它對輸入有效,但對textarea不起作用。有人可以幫忙嗎?Textarea顏色,bordercolor不會更改
$(document).on("click", '.btn-info.mailContact', function() {
values = {
Onderwerp: $('.Subject').val(),
Text: $('.TheMessage').value,
};
if ($('.Subject').val() != "" && $('.TheMessage').val() != "") {
State.sendContactMail(values);
window.location.href = '/confirmation';
} else {
Onderwerp.style.color = Onderwerp.value === "" ? "#f00" : "#0f0";
Onderwerp.style.borderColor = Onderwerp.value === "" ? "#f00" : "#0f0";
Text.style.color = Text.value === "" ? "#f00" : "#0f0";
Text.style.borderColor = Text.value === "" ? "#f00" : "#0f0";
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="form-control Subject" id="Onderwerp" placeholder="Vul je onderwerp hier in"/>
<textarea class="form-control TheMessage" id="Text" wrap="soft" placeholder="Vul je bericht hier in"></textarea>
<a id="btn-mailContact" class="btn btn-info mailContact">Verstuur contactformulier</a>
非常感謝您 –
沒有問題,是它的工作? –
部分地,我得到了我所要求的,但與Text.value ===「」? 「#f00」:「#0f0」;當它不是空的時候,它變回綠色,我沒有用.CSS達到這個目的 –