Method of jQuery Form Form Values

  • 2021-07-10 18:22:08
  • OfStack

Before, js took the values of form form one by one, and it was easy to make mistakes and annoying after more than one quantity. Thank those who are willing to share.

The page defines form, and specifies id value for form. As long as the elements in it need key values, they are given name attribute, and name value is equal to the parameter name that can be recognized by the background.


<form method='post' id="punishformID">
      <input hidden="hidden" name="Stu" value=@Model.Stu>
       <input hidden="hidden" name="StuRuleIDs" value=@Model.StuRuleIDs>
    </form>
  </div>
  <div style="margin-top:20px; padding-left:300px;">
    <button type="button" class="w-button w-button-submit" onclick="isagree();"> Determine </button>
   </button>
  </div>

function isagree() {
  var obj = $('#punishformID').serialize();
  $.ajax({
    type: "POST",
    url: "/Discipline/IsAgree",
    data: obj,//  Form to submit 
    success: function (msg) {
      easyuiAlert(msg);
    },
    error: function (error) {
      easyuiAlert(error);
    }
  });
}

$('#punishformID').serialize(); Is to take the above form value, the result is object, can be directly passed to the background.


Related articles: