0
我需要爲輸入的背景着色一個函數。而已。 我將在稍後調用該函數。我正在使用它進行表單驗證。我需要爲輸入文本的背景製作一個函數
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>
確保'返回FALSE'和'沒有定義pass1' 。 – gdoron