JQuery implementation Get Form form content and binding data to Form form operation analysis

The instance of this article describes the jQuery implementation to obtain the Form form content and binding data to the Form form operation. Share to everyone for reference, specifically as follows:

In the process of day-to-day development, it is inevitable that the Form form will be used, we need to get the data saved to the database, or get a string JSON data in the background, To bind the data to the Form form, I have written a JQuery, FormHelp plugin, which is also very simple:

Gets the data of the form: $ ("# formID"). SERIALIZEJSON ();

$ (“# formid”). setform (json);

jQuery.FormHelp / ** * Sequence sequence in FORM into JSON * The same Checkbox with a semicolon sprayed * @Param {Dom} specified Selector * @Param {Obj} Requires stitching JSON object * @Method serializejson * * / $. Fn.serializejson = function (●tring) {var serializeobj = {}, array = this.serialiZeaRray (); $ ). each (function () {if (serializeobj [this.name]) {serializeobj [this.name] + = ‘;’ + this.Value;} else {serializeobj [this.name] = this.Value;}} ); if (otherString! = Undefined) {Var otHERARRAY = Otherstring.split (‘;’); $ (ortho). Each (Function () {var odhersplitarray = this.split (‘:’); serializeobj [帖子 帖子 帖子 帖子 帖子 帖子 帖子 帖子 帖子] } return serializeObj;}; / ** * Assign JOSN object to form * @Param {DOM} specified selector * @Param {Obj} need to assign a value to Form * @Method SerializeJson * * / $. fn .SETFORM = Function (JsonValue) {var obj = this; $. Each (JsonValue, Function (Name, IVAL) {var $ ONPUT = Obj.Find (“INPUT [Name =” + Name + “]”); if ($ OInput.attr (“type”) == “Checkbox”) {if (ival! == null) {var checkboxobj = $ (“[name =” + name + “]”); var checkRay = ival.split (“; “); for (var i = 0; i

HTML test code
  <checkboxObj.length;i++){
          for(var j=0;j<checkArray.length;j++){
            if(checkboxObj[i].value == checkArray[j]){
              checkboxObj[i].click();
            }
          }
        }
      }
    }
    else if($oinput.attr("type")=="radio"){
      $oinput.each(function(){
        var radioObj = $("[name="+name+"]");
        for(var i=0;i<radioObj.length;i++){
          if(radioObj[i].value == ival){
            radioObj[i].click();
          }
        }
      });
    }
    else if($oinput.attr("type")=="textarea"){
      obj.find("[name="+name+"]").html(ival);
    }
    else{
      obj.find("[name="+name+"]").val(ival);
    }
  })
}

 

jQueryformhelp exercises

  $ ("# form"). Setform ({A: 'Zhang Sanjia) can consider', B: 'King 5', C: 'Wang 5th , D: 'Nishi Yaldjlkfjal', E: 7, F: '8; 10', I: 'King'};}; function submitform () {console.log ($ "" # form "). Serializejson 'ID: 12; Name: 13;'));}              5   6 
7
Xiao
Small
Use online HTML / CSS / JavaScript code running tool http://tools.jb51.net/code/htmljsrun Test Running Effects is as follows:
More about JQuery Related Contents Readers can view this topic: "jQuery form operation skills summary", "jQuery operation JSON data skills summary", "jQuery common plugin and usage summary" , "JQuery extension skill summary", "jQuery form (TABLE) Operation Skills Summary "and" JQuery Selector Summary "
I hope this article will help you jQuery program.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment