jquery serialize()方法可以序列化表单值为字符串

<form>
  <div><input type="text" name="a" value="1" id="a" /></div>
  <div><input type="text" name="b" value="2" id="b" /></div>
  <div><input type="hidden" name="c" value="3" id="c" /></div>
  <div>
    <textarea name="d" rows="8" cols="40">4</textarea>
  </div>
  <div><select name="e">
    <option value="5" selected="selected">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
  </select></div>
  <div>
    <input type="checkbox" name="f" value="8" id="f" />
  </div>
  <div>
    <input type="submit" name="g" value="Submit" id="g" />
  </div>
</form>


$('form').submit(function() {
  alert($(this).serialize());
  return false;
});

输出:
a=1&b=2&c=3&d=4&e=5


posted @ 2016-04-05 14:16  jiapeng  阅读(702)  评论(0编辑  收藏  举报