当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery Form表单取值的方法

jQuery Form表单取值的方法

2019年03月30日  | 移动技术网IT编程  | 我要评论

之前js取form表单的值都是一个一个的取,数量一多之后容易出错而且烦透了。感谢那些愿意分享的人。

页面定义form,并给form指定id值,里面的元素只要是需要键值对应的都赋予name属性,并且name值等于后台能识别的参数名。

<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();">确定</button>
   </button>
  </div>
function isagree() {
  var obj = $('#punishformid').serialize();
  $.ajax({
    type: "post",
    url: "/discipline/isagree",
    data: obj,// 要提交的表单
    success: function (msg) {
      easyuialert(msg);
    },
    error: function (error) {
      easyuialert(error);
    }
  });
}

$('#punishformid').serialize();就是取上面form的值,得到的是object,可以直接传递给后台。

以上所述是小编给大家介绍的jquery form表单取值的方法,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网