怎么用JS实现 按钮功能的循环执行?
如图,点击‘提交’按钮变成‘继续添加’同时文本框变灰且只可读,再次点击‘继续添加’文本框变回原来可写,按钮变成‘提交’。一直可以循环执行。JS代码怎么写?下面是我写的部分...
如图,点击‘提交’ 按钮变成 ‘继续添加’同时文本框变灰且只可读, 再次点击 ‘继续添加’ 文本框变回原来可写,按钮变成‘提交’。一直可以循环执行。 JS代码怎么写?
下面是我写的部分代码,功能都实现了,只是我不知道怎么循环执行?
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>按钮初步2</title></head><body>公司<input id="in1" name="in1" type="text" ><br/>账号<input id="in2" name="in2" type="text" ><br/>密码<input id="in3" name="in3" type="password"><br/><input id="btn1" name="btn1" type="button" value="提交"><script> var ttt = document.getElementById('btn1').value; var bbb = document.getElementById('btn1'); if (ttt == '提交') { bbb.onclick = function () { isreadonly(); changebutton1(); } } if (ttt == '继续添加') { alert(ttt); bbb.onclick = function () { 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('btn2').value = '提交'; }</script></body></html> 展开
下面是我写的部分代码,功能都实现了,只是我不知道怎么循环执行?
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>按钮初步2</title></head><body>公司<input id="in1" name="in1" type="text" ><br/>账号<input id="in2" name="in2" type="text" ><br/>密码<input id="in3" name="in3" type="password"><br/><input id="btn1" name="btn1" type="button" value="提交"><script> var ttt = document.getElementById('btn1').value; var bbb = document.getElementById('btn1'); if (ttt == '提交') { bbb.onclick = function () { isreadonly(); changebutton1(); } } if (ttt == '继续添加') { alert(ttt); bbb.onclick = function () { 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('btn2').value = '提交'; }</script></body></html> 展开
展开全部
用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 = '提交';
}
应用:可将上诉代码中的文字替换,实现其它类型的循环执行。
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 = '提交';
}
应用:可将上诉代码中的文字替换,实现其它类型的循环执行。
展开全部
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 = '提交';
}
追问
我我我去去去,高手哇,膜拜!!
高手,你这是用的什么软件哇???求做朋友!!!
追答
来嘛来嘛来嘛,朋友,编辑器右上角可以选择代码类型,粘在里面就自动高亮了!!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询