问题描述:我页面中有这样多个表单,我都是这个定义的,当我点击确定按钮时,此时能够获得相对应的表单对象,我该怎么获取到他的两个值呢?

解决方案:

页面元素

<form id="form1">
<lable>姓名:</lable>
<input type="text" class="user_name">
<lable>电话:</lable>
<input type="text" class="user_tel">
<span class="button">确定</span>
</form>
<form id="form2">
<lable>姓名:</lable>
<input type="text" class="user_name">
<lable>电话:</lable>
<input type="text" class="user_tel">
<span class="button">确定</span>
</form>
<form id="form3">
<lable>姓名:</lable>
<input type="text" class="user_name">
<lable>电话:</lable>
<input type="text" class="user_tel">
<span class="button">确定</span>
</form>

jquery实现方法(自己任意添加一个jquery库即可)

$(function(){
$('.button').each(function(){
$(this).click(function(){
var name = $(this).parent('form').find('.user_name').val();
var tel = $(this).parent('form').find('.user_tel').val();
console.log(name);
console.log(tel);
});
});
})

  

jquery如何获取对应表单元素?的更多相关文章

  1. jquery easyui将form表单元素的值序列化成对象

    function serializeObject(form){ var o={}; $.each(form.serializeArray(),function(index){ if(o[this['n ...

  2. jquery的attr禁用表单元素的方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  3. 获取form表单元素值的4种方式

    <html><head><title></title><script type="text/javascript"> f ...

  4. jQuery name属性与checked属性结合获取表单元素值

    var paytype = $("input[name='paytype']:checked").val(); alert(paytype); input元素下名称为paytype ...

  5. jquery获取表单元素与回显

    一.获取哦表单元素 dcoument表单文本对象的集合 all[] 对所有html元素的访问 forms 返回对文档中所有form对象的引用 forms[1] 对所有form对象引用 <scri ...

  6. jQuery操作Form表单元素

    Web开发中常常须要操作表单,form表单元素有select.checkbox.radio.textarea.button.file.text.hidden.password等. 当中checkbox ...

  7. 遍历form表单里面的表单元素,取其value

    form.elements 获取所有表单元素 form 表单 <form action="http://localhost:1995/api/post" class=&quo ...

  8. jQuery获取Select选择的Text(非表单元素)和 Value(表单元素)(转)

    jQuery获取Select选择的Text和Value: 语法解释: . $("#select_id").change(function(){//code...}); //为Sel ...

  9. jQuery 获取、设置表单元素的值

    获取表单元素值: 文本框,文本区域: $("#txt").attr("value"): 多选框 checkbox:$("#checkbox_id&qu ...

随机推荐

  1. selendroid之toast处理

    最近发现原来处理toast的操作失效了.仔细看了下原来的API.决定用switchTo来解决.driver.switchTo().defaultContent().findElement(By.id( ...

  2. WebService小例子———

    WebService学习(刚开始) ———————————————————————————————————————————————————————————————————— WebService:跨平 ...

  3. Java Hotspot client模式和server模式的区别

    当虚拟机运行在-client模式的时候,使用的是一个代号为C1的轻量级编译器, 而-server模式启动的虚拟机采用相对重量级,代号为C2的编译器. C2比C1编译器编译的相对彻底,服务起来之后,性能 ...

  4. htmlunit模拟登录

    htmlunit jar项目路径http://sourceforge.net/projects/htmlunit/files/htmlunit/ demo代码如下 public class AutoL ...

  5. 通过yum安装最新服务

    给yum添加所安装服务最新rpm源  #这里用mysql为例 # wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm # y ...

  6. OO思想举例,控制翻转,依赖注入

    (转自kumaws,原帖地址:http://www.cnblogs.com/kumaws/archive/2009/04/06/from_interface_to_DependencyInjectio ...

  7. SQA计划与测试规程

    长大一条龙之SQA计划与测试规程 一.SQA计划 1.软件工程 我们之进行开发之前,在弄完需求分析的前提下,进行了软件一些列的建模和评估,我们建立了基于类的模型图类图,基于场景的模型图流程图,再对这些 ...

  8. POJ 3461 Oulipo 【KMP统计子串数】

    传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace【树状数组维护区间最大值】

    任意门:https://nanti.jisuanke.com/t/31459 There's a beach in the first quadrant. And from time to time, ...

  10. Hibernate的属性配置

    Hibernate配置属性 hibernate.dialect Hibernate方言(Dialect)的类名 - 可以让Hibernate使用某些特定的数据库平台的特性 取值. full.class ...