提交后,改变错误信息框输入的文字颜色

解决方案 »

  1.   

    change the style.color property
      

  2.   

    <script>
    function mytest()
    {
    document.all.test.style.color="red";
    }
    </script><input type="text" name="test" value="111">
    <input type="button" name="but" value="点击" onclick="mytest()">
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <script>
    function myFun()
    {
    var txt = document.getElementById("txt");
    //txt.value = msg;
    if ( txt.value.search("^/[0-9]+$/") != -1)
    {
    //alert("d");
    return true;
    }
    else
    {
    //alert("e");
    txt.style.backgroundColor = "red";
    return false;
    }
    }
    </script>
    </head><body>
    当文本框里输入的不是数字时,文本框变成红色
    <input type="text" id="txt">
    <input type="button" onClick="return myFun();" value="测试">
    </body>
    </html>
    作了一个小例子,希望对你有帮助