Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

javascript - setAttribute is not working when i tried to set disabled attribute

I have developing a simple wizard form in which the content is divided into four section. I have written CSS to show target section.

section {
    display: none;
}

section:target {
    display: block;
}

while i click next button i am trying to setAttribute disabled true for hidden section elements and try to remove disabled attribute from target section input elements from JavaScript.

var divElem = document.querySelector(".section-1");
var inputElements = divElem.querySelectorAll("input, select, textarea");

for (var i = 0; i < inputElements.length; i++) { 
  inputElements[i].setAttribute("disabled","true");
}

document.querySelector("#form-wizard").action = "#wizard-p-1";

var divElem2 = document.querySelector(".section-2");
var inputElements2 = divElem2.querySelectorAll("input, select, textarea");
for (var j = 0; j < inputElements2.length; j++) { 
  inputElements2[j].removeAttribute("disabled");
}

There is no error but it didn't set or remove any attribute.

Please help me to resolve this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...