论坛首页 Web前端技术论坛

(求助)jQuery得到所有表单信息

浏览 4719 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-07-03  
第一次用到jQuery,请教一个问题。自己做了一个例子,得到页面中的 输入框,下拉框,多选框等等的信息。用的是 jQuery Form Plugin.代码如下:
html页面
<Html>
<HEAD>
  <TITLE> New Document </TITLE>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <script src = "js/jquery.js"></script>
  <script src = "js/form.js"></script>
  <script src = "js/common.js"></script>
</HEAD>
<BODY>
     <form id="myForm" action="#" method="post">
        Name: <input type="text" name="name" value = "Ozone" />
        Comment: <textarea name="comment" value = "I am a boy">Thank you!</textarea>
       <input type = "checkbox" value = "hello" checked/>Hello
       <input type = "checkbox" value = "welcome"/>Welcome
       <input type="submit" value="Submit Comment" />
    </form>
</BODY>
</HTML>

common.js
$(document).ready(function() {
     queryString = $('#myForm').formSerialize();
     alert("String---->"+queryString);
});

为什么弹出框中得到的只有输入框的信息?没有多选等其他信息.

如果把common.js修改为:
$(document).ready(function() { 
     var queryString = $('#myForm').formSerialize();
     alert("--->"+queryString)
}); 

弹出框中得到的信息为空.
那位朋友可以给说说什么原因吗? 顺便说一下,感觉jQuery的文档不太详细吧,看了半天英文的,也没弄出个所以然来! 郁闷阿!
   发表时间:2007-07-03  
建议用firebug调试,然后可以看对象的所有方法,以及返回值,个人觉得比看文档方便……
0 请登录后投票
   发表时间:2007-07-03  
因为你其他input没有name。
0 请登录后投票
   发表时间:2007-07-25  
发现问题所在了,是因为checkbox不需要value属性,去掉value属性,就可以解决问题了。修改如下:
   1. <Html>  
   2. <HEAD>  
   3.   <TITLE> New Document </TITLE>  
   4.   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
   5.   <script src = "js/jquery.js"></script>  
   6.   <script src = "js/form.js"></script>  
   7.   <script src = "js/common.js"></script>  
   8. </HEAD>  
   9. <BODY>  
  10.      <form id="myForm" action="#" method="post">  
  11.         Name: <input type="text" name="name" value = "Ozone" />  
  12.         Comment: <textarea name="comment" value = "I am a boy">Thank you!</textarea>  
  13.        <input type = "checkbox" checked/>Hello  
  14.        <input type = "checkbox" />Welcome  
  15.        <input type="submit" value="Submit Comment" />  
  16.     </form>  
  17. </BODY>  
  18. </HTML>  

0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics