我希望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达到这个目的 –