使用jquery从HTML表单获取值 [英] Get the value from HTML form using jquery

查看:195
本文介绍了使用jquery从HTML表单获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取HTML表单使用jquery的值。

在这里我的表单是两个div info1和info2,在jquery中我有两个变量存储和store2

info1的值保存在变量存储器中,info2的值保存在store2中。

但是由于这个原因,代码中的某些错误没有运行。见下面的代码。

这是代码:

I want to get the values if HTML form using jquery.
In my form here is two div info1 and info2 and in the jquery I have two variable store and store2
value of info1 is save in variable store and value of info2 is save in store2.
But here is the some error in the code due to this reason this is not run. see the code below.
Here is code:

<form>
      <div id="info1">
         <input type="text" />
         <input type="text" />
         <input type="text" />
      </div>
      <div id="info2">
         <input type="text" />
         <input type="text" />
      </div>
   <input type="button" id="btn" value="click" />
 </form>

JQUERY:

$(document).on('click','#btn',function(){
    var store = [];
    var store2 = [];
     $('#info1 :input[type="text"]').map(function(){
        var values = $(this).val();
       store.push({values:values});
          });
     $('#info2 :input[type="text"]').map(function(){
        var values = $(this).val();
       store2.push({values:values});
          });
     });

这段代码无效。我认为错误在这里 $('#info1:input [type =text]')

请解决这个问题。

Thankx。

This code is not working. I think the error is here $('#info1 :input[type="text"]').
Please solve this.
Thankx.

推荐答案

您的代码正在工作,检查控制台中的值,试试这个:

Your code is working, to check the values in console, try this:

 $(document).on('click','#btn',function(){
     var store = [];
     var store2 = [];

     $('#info1 :input[type="text"]').map(function(){
        var values = $(this).val();
       store.push({values:values});
          });
     $('#info2 :input[type="text"]').map(function(){
        var values = $(this).val();
       store2.push({values:values});
          });

     console.log(store);
     console.log(store2); 
 });

这篇关于使用jquery从HTML表单获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆