如何在验证时更改文本框的背景颜色 [英] how to change background color of textboxes on validation
本文介绍了如何在验证时更改文本框的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要精确,
On输入不正确的值到文本框我需要获得红色背景并再次修正红色背景值应该消失。它应该是Javascript。
我可以将背景颜色更改为红色但是在修正红色值时仍然可以。
我需要在正确验证时清除红色。
解决方案
您好,
尝试此解决方案:
< input type =textid =subEmailonkeyup =checkFilled();/>
JavaScript:
function checkFilled(){
var inputVal = document.getElementById( subEmail)。值跨度>;
if (inputVal == Red ){
document.getElementById( subEmail)。style.backgroundColor = 红色;
}
else if (inputVal == white){
document.getElementById( < span class =code-string> subEmail)。style.backgroundColor = white跨度>;
}
}
根据您的要求,您可以更改颜色和输入值验证。
HTML
< input type =textid =phonemaxlength =10>
JavaScript:
(document).ready (function(){
To be PRECISE,
On Entering improper value to textbox i need to get red background & again on correcting the value red background should disappear. It should be in Javascript.
I am able to change background color to red but on correcting the value the red remain.
I need to clear red color on proper validation.
解决方案
Hi,
Try this solution :
<input type="text" id="subEmail" onkeyup="checkFilled();"/>
JavaScript :
function checkFilled() { var inputVal = document.getElementById("subEmail").value; if (inputVal == "Red") { document.getElementById("subEmail").style.backgroundColor = "Red"; } else if(inputVal == "white"){ document.getElementById("subEmail").style.backgroundColor = "white"; } }
As per your requirnment you can change the colors and input value validation.
HTML
<input type="text" id="phone" maxlength="10">
JavaScript :
(document).ready(function() {
这篇关于如何在验证时更改文本框的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文