怎么用JS实现 按钮功能的循环执行?

怎么用JS实现 按钮功能的循环执行?
如图,点击‘提交’ 按钮变成 ‘继续添加’同时文本框变灰且只可读, 再次点击 ‘继续添加’ 文本框变回原来可写,按钮变成‘提交’。一直可以循环执行。 JS代码怎么写?
下面是我写的部分代码,功能都实现了,只是我不知道怎么循环执行?

按钮初步2公司
账号
密码

用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 = '提交';
}

← 上一篇: 下一篇: →