JS Disable the implementation of all the controls on the page (with demo source download) _javascript Tips

Source: Internet
Author: User
Tags tagname

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.