JavaScript common method of finishing _javascript skills

Source: Internet
Author: User

Sorting out some of the common methods of JS, including verification Ah, select the reverse AH, Ajax request Ah, and so on, because it is their own use, write is relatively simple, even if you like to take it, do not like to pull

Tools.min.js

/** * JS Common class library file * Date Created: 2015-05-13 * Creator: mction * * (function () {var D = document;
  var W = window;
  var Postfix = '. php ' var _id = function (ID) {return document.getElementById (ID);
      Check = {Input:function (name,value,message) {var Input = $ (': Input[name= ' "+name+ ']");
        if (input.val () = = Value) {input.focus ();
        alert (message);
      return true;
    return false; }, Phone:function (Name) {/* * Unicom segment: 130/131/132/155/156/185/186/145/176; * Electrical signal segment: 133/153/180/181/189 /177; * Mobile number: 134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178/var Reg = /^1 (30|31|32|55|56|85|86|45|76|33|53|80|81|89|77|34|35|36|37|38|39|50|51|52|57|58|59|82|83|84|87|88|47|78) [0-9
      ]{8}$/;
      var Phone = $ (": Input[name= '" +name+ ""); if (!
        Reg.test (Phone.val ())) {Phone.focus ();
      return true;
    return false; }, Email:function (Name) {var Reg =/^[a-za-z0-9_]+@[a-z0-9]+\.
      [a-z]+$/;
      var Email = $ (": Input[name= '" +name+ ""); if (!
        Reg.test (Email.val ())) {Email.focus ();
      return true;
    return false;
      }, Username:function (usernamemark,message) {var Reg =/^[\d]{8}$/;
      var UserName = $ (": Input[name= '" +usernamemark+ ")"); if (!
        Reg.test (Username.val ())) {Username.focus ();
        alert (message);
      return true;
    return false; }, Password:function (Name) {var Reg =/^ ([a-z]+) $|^ ([a-z]+) $|^ ([0-9]+) $|^ ([-' =\\\[\]; ', \.\/~!@#\$%\^&\*\ (\) _ +\|\{}: "<>\?" +)$|^. {0,5}$|^.
      {18,}$/var Password = $ (": Input[name= '" +name+ "]");
        if (Reg.test (Password.val ())) {Password.focus ();
      return true;
      }else{return false;
  }
    }
  };
      member = {login:function () {var UserName = $ (": Input[name= ' UserName ']");
      var PassWord = $ (": Input[name= ' PassWord ']");
   if (Check.username ("UserName", "Incorrect user name format")) {     return false;
      } if (Check.input ("Password", "", password cannot be null)) {return false;
          } $.ajax ({url: "/user/action" +postfix, type: "POST", data:{Request: "Login", Username:UserName.val (), Password:PassWord.val ()}, DataType: "JSON", Success:functio
            N (Data) {if (data.state!=) {alert (data.message);
          return false;
          }else{location.href= "/user/member" +postfix;
    }
        }
      });
    }, Logout:function () {location.href = '/user/logout ' +postfix;
  }
  }; public = {Hi:function () {alert (' Hi ');}, Box_all_sel:function (class,allchecked) {//All select reverse var Input = D.geteleme
      Ntsbytagname ("input");
      var boxlist = [];
          for (I =0;i<input.length;i++) {if (Input[i].type = = "checkbox" && input[i].classname = = Class) {
        Boxlist.push (Input[i]);
  } if (allchecked) {      For (I in boxlist) {boxlist[i].checked = true;
        }}else{for (I in boxlist) {boxlist[i].checked = boxlist[i].checked? false:true;
      }}, After:function (New,tar) {if (typeof tar = = ' string ') {var Parent = _id (TAR);
      }else{var Parent = Tar;
      } if (Parent.parentnode = = Parent) {Parent.parentNode.appendChild (NEW);
      }else{Parent.parentNode.insertBefore (new,parent.nextsibling); }, Requests:function (O,class) {//Bulk request//url.request.message.input.inputmessage.inputvalue var Data = $ ("."
      + Class + ": Checked"). Serialize ();
        if (Data = = ") {alert (" You do not select any items ");
        alert (O.options[0].value);
        O.value = O.options[0].value;
      Return
      var Temparr = O.value.split ('. '); if (! Temparr[0] | | !
        Temparr[1]) {//Verify URL and Action alert ("error: Missing required parameters");
        O.value = O.options[0].value; RetUrn
      Data + + "&request=" + temparr[1]; var message = "Confirm deletion of selected items?"
      ";
      if (Temparr[2]) {//validate and set the hint message = temparr[2];
        } if (confirm (message)) {var Input = false;
        if (Temparr[3]) {//verify and set whether to receive user input = true;
          } if (Input = = ' True ') {var inputval = prompt (Temparr[4],temparr[5]);
        Data + + "&input=" + inputval; } $.ajax ({URL: "./" +temparr[0]+postfix, type: ' Get ', Data:data, DataType: ' J
            Son ', Async:false, Success:function (Data) {alert (data.message);
          Location.reload (TRUE);
      }
        }); Request: {//Single-dose requests Data: ', Method: ', DataType: ', Async: ', Setdata:fu Nction (Options,method,datatype,async) {this.
        Data = Options; This. Method = typeof Method = = ' undefined '?
        ' Get ': method; This. DataType = typeof DataType = = ' undefined '?
        ' JSON ': DataType; This. Async = typeof Async = = ' undefined '?
        True:async;
      return this; }, Send:function (url,call,im,message) {if (! Message} {message = Confirm deletion?
        ";
              } if (typeof call!= ' function ') {call = function (Data) {switch (This.datatype) {
              Case ' text ': Alert (Data);
          Default:alert (Data.message); break} location.reload (True);
        } var CF = true;
        var CFM = true;
        var LId; 
        if (typeof im!= ' undefined ' && im = false) {CF = false} if (cf &&!confirm (message)) {CFM = false;} if (CFM) {$.ajax {url:url, type:this. Method, Data:this. Data, Datatype:this. DataType, Async:this. Async, Beforesend:function (O) {LId = Public.Loading.Open ("in Process");}, SUCCEss:call, Error:function (e,info,eo) {alert (E.statustext + ":" + E.responsetext);}, Complete:functio
          N (O) {Public.Loading.Close (LId);}
        }); }}, Desc: {descid: ', Display:function (o,message) {var Id = parseint (Math.random (
        ) * 1000); This.
        Descid = Id;
        var Desc = d.createelement (' description ');
        Desc.id = ID;
        desc.innerhtml = message;
        Desc.style.width = "200px";
        Desc.style.border = "1px solid #dfdfdf";
        Desc.style.backgroundColor = "#fff";
        Desc.style.lineHeight = "normal";
        Desc.style.position = "absolute";
        Desc.style.top = o.offsettop + ' px ';
        Desc.style.marginLeft = "5px";
        Public.after (Desc,o);
      O.setattribute ("onblur", ' Public.Desc.Close () '); }, Close:function () {$ ("#" +this.)
      DESCID). Remove (); Options: {file_input:function (OBJ) {//Add File selection box var chars = ' ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678 ';
        var objname = ';
        for (var i = 0; i < 5; i++) {objname + = Chars.charat (Math.floor (Math.random () * chars.length));
        var inputfile = d.createelement ("input");
        Inputfile.type = "File";
        Inputfile.name = objname;
        inputfile.accept = "image/*";
        var a = D.createelement ("a");
        A.href = "javascript:;";
        A.style.marginleft = "300px";
        a.innerhtml = "Delete";
        A.setattribute ("onclick", ' $ ("div"). Remove ("# ' +objname+ ')");
        var div = d.createelement ("div");
        Div.id = objname;
        Div.style.padding = "5px";
        Div.style.borderBottom = "1px solid #cccccc";
        Public.after (Div,obj);
        _ID (objname). appendchild (Inputfile);
      _ID (objname). appendchild (A); 
        }, Loading: {windowid: ', open:function (message) {var Id = parseint (Math.random () * 1000); This.
        Windowid = Id; var Div = D.createelement ("div");
        Div.id = ID;
        Div.style.width = "80%";
        Div.style.height = "50px";
        Div.style.backgroundColor = "#000";
        Div.style.opacity = "0.5";
        Div.style.borderRadius = "10px";
        Div.style.position = "fixed";
        Div.style.top = (w.innerheight-50)/2 + "px";
        Div.style.left = "10%";
        var p = d.createelement ("P");
        p.style.textalign = "center";
        P.style.color = "#fff";
        P.style.lineheight = "50px";
        P.style.height = "50px";
        var Img = d.createelement (' img ');
        IMG.SRC = "/phps/public/images/loading.gif";
        Img.style.marginBottom = " -5px";
        if (message) {p.innerhtml = message;
        }else{p.innerhtml = "in Process";
        P.appendchild (IMG);
        D.getelementsbytagname ("Body") [0].appendchild (DIV); _ID (this.
        WINDOWID). appendchild (P);
      return Id; }, Close:function (ID) {if (typeof ID!= ' undefined ' && ID!= null) {D.getelementsbytagname ("body") [0].removechild (_id (id)); }else if (this. Windowid!= ') {d.getelementsbytagname ("body") [0].removechild _id (this.
        WINDOWID)); }}, Tabs: {tabsnum:1, Tablistid: ', Windowid: ', New_tabs:function (tablis Tid,windowid,openurl,pagetitle) {this.
        Tablistid = Tablistid; This.
        Windowid = Windowid;
        var iframelist = _id (Windowid). getElementsByTagName ("iframe");
        alert (iframe.length);
        for (I = 0;i < Iframelist.length;i + +) {Iframelist[i].style.display = "none";
        var tablist = _id (Tablistid). getElementsByTagName ("Li");
        alert (tablist);
        for (I = 0;i < Tablist.length;i + +) {tablist[i].classname = "";
        var Iframe = d.createelement ("iframe"); Iframe.id = "IFR" +this.
        Tabsnum;
        IFRAME.SRC = OpenURL;
       Iframe.frameborder = 0; Iframe.width = "100%";
        Iframe.height = "100%";
        var a = D.createelement ("a");
        A.href = "javascript:;"; a.ID = "IFA" +this.
        Tabsnum;
        a.innerhtml = PageTitle;
        A.setattribute ("Data-if", iframe.id);
        A.setattribute ("onclick", "Public.Tabs.View (This)");
        var Li = d.createelement ("Li"); Li.id = "IFL" +this.
        Tabsnum;
        Li.classname = "on";
        Li.setattribute ("Data-if", iframe.id);
        var close = d.createelement ("a");
        Close.href = "javascript:;";
        close.innerhtml = "X";
        Close.setattribute ("Data-li", li.id);
        Close.setattribute ("Data-if", iframe.id);
        Close.setattribute ("onclick", "Public.Tabs.Close (This)"); This.
        tabsnum++;
        _ID (Tablistid). appendchild (Li);
        _ID (li.id). appendchild (A);
        _ID (li.id). appendchild (Close);
      _ID (Windowid). appendchild (Iframe); }, View:function (O) {var iframelist = _id (this. WINDOWID). getElementsByTagName("iframe");
        for (I = 0;i < Iframelist.length;i + +) {Iframelist[i].style.display = "none"; var tablist = _id (this.
        Tablistid). getElementsByTagName ("Li");
        for (I = 0;i < Tablist.length;i + +) {tablist[i].classname = "";
        } o.parentnode.classname = "on";
      _id (O.getattribute (' data-if ')). Style.display = "block";
        }, Close:function (O) {var Lio = _id (O.getattribute ("Data-li"));
        var IFO = _id (O.getattribute ("data-if"));
        if (lio.nextelementsibling) {var displayli = lio.nextelementsibling; }else{var tablist = _id (this.
          Tablistid). getElementsByTagName ("Li");
        var displayli = tablist[tablist.length-2];
        } if (ifo.nextelementsibling) {var displayif = ifo.nextelementsibling; }else{var iflist = _id (this.
          WINDOWID). getElementsByTagName ("iframe");
     var displayif = _id (iflist[iflist.length-2].id);   } LiO.parentNode.removeChild (Lio);
        IFO.parentNode.removeChild (IFO);
        Displayli.classname = "on";
      DisPlayIF.style.display = "block";
}
    }
  };
 })();

These are the basics of JavaScript, if it is a novice, I think these are not enough for you to learn, you can find some information to complete the study of JavaScript.

These are some of the JavaScript based friends, you can first browse this knowledge, perhaps there are you have forgotten or omitted, memory of JavaScript for you to continue to learn Ajax after the great help.

Related Article

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.