简体   繁体   中英

Background color of Text-box

I want the background color in the text-box to stay for at least 5 seconds after i click the submit button

but it is disappearing as soon as i click submit button.

This is my code...

<!DOCTYPE>
<html>
<head>
<title>Text Boxes With Aplhabets </title>
</head>
<body>`enter code here`

<script type="text/javascript">

 frm.alphabets.value="";
function AllowAlphabets(){
               if (!frm.alphabets.value.match(/^[a-zA-Z]+$/) )
               {

                    frm.alphabets.focus(); 
                    frm.alphabets.style.background="Red";
                    //alert("Please Enter only alphabets");
               }

}      
</script>

<form name="frm"   onsubmit="return AllowAlphabets()">
Enter Aplhabets: <input type="text" name="alphabets" />
<input type = "submit" value = "Submit">
</form>
<br;>
</body>
</html>

use setTimeout()

example :

setTimeout(myFunction, 2000);

or

setTimeout(function () {

//code here
}, 2000);

reference : MDN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM