简体   繁体   English

文本框的背景色

[英]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 我希望在文本框中单击“提交”按钮后,背景颜色至少保留5秒钟

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() 使用setTimeout()

example : 例如:

setTimeout(myFunction, 2000);

or 要么

setTimeout(function () {

//code here
}, 2000);

reference : MDN 参考: MDN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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