【问题标题】:I need to make a function that colors the background of an input text我需要制作一个为输入文本的背景着色的函数
【发布时间】:2014-02-10 09:16:33
【问题描述】:

我需要创建一个为输入背景着色的函数。就是这样。 稍后我将调用该函数。我正在使用它进行表单验证。

function makeRed(input) {  
        input.style.backgroundColor = "red";
    }

问题是当我点击提交时,红色只是闪烁。它不会保持红色。 当我调用该函数时,我会这样做:

function samepass() {
        var a = document.getElementById("pass1").value; //pass1 is the id of the input in HTML
        var b = document.getElementById("pass2").value;
        if (a != b){
            makeRed(pass1);
        }
    }

HTML:

<form action="tema.html" method="post" onSubmit="return samepass()">                    

                    <label for="pass1" class="lbl">Password: </label>
                    <input type="password" id="pass1" name="pass1" class="inp"/><br /><br />


                </form>

【问题讨论】:

  • 确保return falsepass1没有被定义。

标签: javascript forms function validation


【解决方案1】:

试试这个

function makeRed(input) {  
        document.getElementById("input").style.backgroundColor = "red";
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多