使用以下JavaScript的function ThisEdit(event){ var eid = event; var btnlabel = document.getElementById("BtnEdit").value;">
我有下面的按钮
<input type='button' id='BtnEdit' value='Edit' onclick='ThisEdit(this)'/>
使用以下JavaScript的
function ThisEdit(event){
var eid = event;
var btnlabel = document.getElementById("BtnEdit").value;
if(btnlabel == "Edit") {
document.getElementById("BtnEdit").value = "Save";
document.getElementById("NT").readOnly = false;
document.getElementById("ND").readOnly = false;
document.getElementById("NU").readOnly = false;
document.getElementById("NT").style.backgroundColor = "White";
document.getElementById("ND").style.backgroundColor = "White";
document.getElementById("NU").style.backgroundColor = "White";
}
if(btnlabel == "Save") {
document.getElementById("BtnEdit").value = "Edit";
document.getElementById("NT").readOnly = true;
document.getElementById("ND").readOnly = true;
document.getElementById("NU").readOnly = true;
document.getElementById("NT").style.backgroundColor = "Gray";
document.getElementById("ND").style.backgroundColor = "Gray";
document.getElementById("NU").style.backgroundColor = "Gray";
}
}
单击按钮时,它只更改按钮标签,并更改输入文本字段(由id‘NT表示)和文本区域字段(由id 'ND’和‘NU’表示)的readonly属性。它不更改输入文本字段和文本区域字段的背景色。
请告诉我,如果我改变背景色的方式是错误的,或有其他的事情,我做错了。
谢谢。
发布于 2015-01-22 21:02:05
代码中的所有内容似乎都是正确的,但请尝试
if(btnlabel.value == "SAVE")
{
..........
}
让我知道它是否有效。
https://stackoverflow.com/questions/28103246
复制相似问题