发布网友 发布时间:2022-04-23 19:10
共2个回答
热心网友 时间:2022-04-20 09:19
用JS实现 点击‘提交’ 按钮变成 ‘继续添加’同时文本框变灰且只可读, 再次点击 ‘继续添加’ 文本框变回原来可写,按钮变成‘提交’。一直可以循环执行:
var bbb = document.getElementById('btn1');
bbb.onclick = function() {
var ttt = document.getElementById('btn1').value;
if (ttt == '提交') {
isreadonly();
changebutton1();
} else if (ttt == '继续添加') {
readwrite();
changebutton2();
}
};
function isreadonly() {
var obj = document.getElementById("in1");
obj.setAttribute("readOnly", true);
obj.style.backgroundColor = "#d2d2d2";
var obj = document.getElementById("in2");
obj.setAttribute("readOnly", true);
obj.style.backgroundColor = "#d2d2d2";
var obj = document.getElementById("in3");
obj.setAttribute("readOnly", true);
obj.style.backgroundColor = "#d2d2d2";
}
function readwrite() {
var obj = document.getElementById("in1");
obj.setAttribute("readOnly", false);
obj.style.backgroundColor = "#ffffff";
var obj = document.getElementById("in2");
obj.setAttribute("readOnly", false);
obj.style.backgroundColor = "#ffffff";
var obj = document.getElementById("in3");
obj.setAttribute("readOnly", false);
obj.style.backgroundColor = "#ffffff";
}
function changebutton1() {
document.getElementById('btn1').value = '继续添加';
}
function changebutton2() {
document.getElementById('btn1').value = '提交';
}
应用:可将上诉代码中的文字替换,实现其它类型的循环执行。
热心网友 时间:2022-04-20 10:37
var bbb = document.getElementById('btn1');
bbb.onclick = function() {
var ttt = document.getElementById('btn1').value;
if (ttt == '提交') {
isreadonly();
changebutton1();
} else if (ttt == '继续添加') {
readwrite();
changebutton2();
}
};
function isreadonly() {
var obj = document.getElementById("in1");
obj.setAttribute("readOnly", true);
obj.style.backgroundColor = "#d2d2d2";
var obj = document.getElementById("in2");
obj.setAttribute("readOnly", true);
obj.style.backgroundColor = "#d2d2d2";
var obj = document.getElementById("in3");
obj.setAttribute("readOnly", true);
obj.style.backgroundColor = "#d2d2d2";
}
function readwrite() {
var obj = document.getElementById("in1");
obj.setAttribute("readOnly", false);
obj.style.backgroundColor = "#ffffff";
var obj = document.getElementById("in2");
obj.setAttribute("readOnly", false);
obj.style.backgroundColor = "#ffffff";
var obj = document.getElementById("in3");
obj.setAttribute("readOnly", false);
obj.style.backgroundColor = "#ffffff";
}
function changebutton1() {
document.getElementById('btn1').value = '继续添加';
}
function changebutton2() {
document.getElementById('btn1').value = '提交';
}
追问我我我去去去,高手哇,膜拜!!
高手,你这是用的什么软件哇???求做朋友!!!
追答来嘛来嘛来嘛,朋友,编辑器右上角可以选择代码类型,粘在里面就自动高亮了!!