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

解决方案:

页面元素

<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. dhtml

    网页换肤:<div> <button>red</button> <button>blue</button> <button>bl ...

  2. Avro-RPC client in Flume

    Avro used in Flume Define the interface of RpcClient public interface RpcClient { public int getBatc ...

  3. apk接入google play邮箱登陆及充值注意事项

    unity3d 接入google play商店相关sdk,相关要求A.环境配置: 1.手机安装谷歌安装器 2.使用谷歌安装器安装Google 服务框架.Google Play服务.Google Pla ...

  4. javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/el/ELResolver错误解决办法

    今天不用eclipse.myeclipse等开发工具,纯手写JSP页面(有点作死)时突然出现以前从来没遇到过的问题,报错如下: HTTP Status 500 - java.lang.NoClassD ...

  5. GitHub无法push的问题

    问题背景 换了台别人用过的电脑想要将文件push到github上,出现下面报错 remote: Permission to *****(我的)/gittest.git denied to *****( ...

  6. oracle_great_integration_译文

    website:https://www.oracle.com/corporate/features/great-integrations.html Great Integrations(伟大的整合) ...

  7. 用AutoHotkey重置Excel的Ctrl+Alt+方向键选择的范围

    当前选择是蓝色单元格,原来的Ctrl+Alt+方向键,是选中[蓝色]到[红色]单元格的区域, 经过脚本修改后,则是[蓝色]到[黄色]的区域,应该更符合日常使用, 特别是表格比较大的时候,一直按住鼠标滚 ...

  8. 真的有用吗?(GitHub)

    为什么要新建一个GitHub账号   一个程序员不知道GitHub,那我就笑笑,呵呵哒.什么是GitHub呢? 就我知道的git,谈一下.Git是一个版本控制软件,这个软件最初是Linux之父林纳斯. ...

  9. 2018中国大学生程序设计竞赛 - 网络选拔赛 1009 - Tree and Permutation 【dfs+树上两点距离和】

    Tree and Permutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  10. js时间日期格式

    Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month &quo ...