转:jquery获取form里的字段值

$(function() {
  $('#submit').click(function() {
    var d = {};
    var t = $('form').serializeArray();
    //t的值为[{name: "a1", value: "xx"},
    //{name: "a2", value: "xx"}...]
    $.each(t, function() {
      d[this.name] = this.value;
    });
    alert(JSON.stringify(d));
  });
});
</script>
<form>
<input id="a1" type="input" value="" name="a1"><br>
<input id="a2" type="input" value="" name="a2"><br>
<input id="a3" type="input" value="" name="a3"><br>
<select id="ax" name="ax">
<option value="0">选项1</option>
<option value="1">选项2</option>
</select><br>
<input id="submit" type="button" value="提交" name="submit">
posted @ 2020-07-31 02:09  大牛等等我  阅读(834)  评论(1编辑  收藏  举报