This article is an example of how JS disables the implementation of all the controls on the page. Share to everyone for your reference, specific as follows:
With the features of the page elements, you can capture all the elements.
function Disableelements (Container,blnhidenbutton) {if (!container) return;
var Aele;
if (navigator.appname = = "Microsoft Internet Explorer")//ie {for (var i=0;i<container.all.length;i++) {
Aele = Container.all[i];
TagName = AEle.tagName.toUpperCase ();
if ((tagname== "SELECT") {aele.disabled = true;
if (tagname== "button" && Blnhidenbutton) {//aele.style.display = "none";//Do not process button) else if (tagname== "INPUT") {if (AEle.type.toUpperCase ()!= "HIDDEN") {if (AE
Le.type.toUpperCase () = = "TEXT") {Readonlytext (Aele);
else if (aEle.type.toUpperCase () = "button") {//do nothing;
else {aele.disabled = true; } if ((AEle.type.toUpperCase () = "button" | |
AEle.type.toUpperCase () = = "SUBMIT") && Blnhidenbutton) {//aele.style.display = ' none ';//Do not treat button}}
else if (tagname== "TEXTAREA") {Readonlytext (Aele);
}} else//non-IE browser {var aele = container.getelementsbytagname ("select");
for (var i=0;i< aele.length;i++) {aele[i].disabled = true;
} Aele = Container.getelementsbytagname ("button");
for (var i=0;i< aele.length;i++) {aele[i].disabled = true;
} Aele = Container.getelementsbytagname ("textarea");
for (var i=0;i< aele.length;i++) {readonlytext (aele[i]);
} Aele = Container.getelementsbytagname ("input"); for (var i=0;i< aele.length;i++) {if (Aele[i].type.touppercase ()!= "HIDDEN") {if (Aele[i].type
. toUpperCase () = = "TEXT") {Readonlytext (aele[i]);
else {aele[i].disabled = true; } if ((Aele[i].type.touppercase () = "button" | | Aele[i].type.touppercase ()= = "SUBMIT") &&blnhidenbutton {aele[i].style.display = "none";
}}} function Readonlytext (objtext) {if (objtext) {//objtext.style.backgroundcolor = ' menu ';
ObjText.style.background = "#E6E6E6";
ObjText.style.color = "BLACK";
Objtext.readonly=true;
}
}
The effect is very good, I will have the button all reserved, if you want to disable the button, you can remove the annotation.
Calling code:
Suppose you have a form named Formeditor that calls the following method:
var myform=document.forms["Formeditor"];
Disableelements (MyForm, ' true ');
Full instance code click here to download the site.
I hope this article will help you with JavaScript programming.