我试图在单击时将文本框中的颜色从蓝色更改为红色,但是,它始终是红色,事件侦听器由于某种原因无法正常工作。
function formFun() {
var textBox1 = document.forms[0].elements[0];
var textBox2 = document.forms[0].elements[1];
var button1 = document.forms[0].elements[2];
var button2 = document.forms[0].elements[3];
textBox2.style.backgroundColor = "blue";
button1.style.backgroundColor = "blue";
button2.style.backgroundColor = "blue";
button1.addEventListener("click", changeColor());
function changeColor() {
textBox1.style.backgroundColor = "red";
}
}
<form name="mForm">
<input type="text" name="in1">
<input type="text" name="in2">
<button name="butt1">click1</button>
<button name="butt2">click2</button>
</form>