xhtml文件中怎么实现循环执行js代码
2017-01-07 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
用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");
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");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询