xhtml文件中怎么实现循环执行js代码

2025-04-08 00:42:30
推荐回答(1个)
回答1:

用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");