jquery如何获取对应表单元素?
问题描述:我页面中有这样多个表单,我都是这个定义的,当我点击确定按钮时,此时能够获得相对应的表单对象,我该怎么获取到他的两个值呢?
解决方案:
页面元素
<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如何获取对应表单元素?的更多相关文章
- jquery easyui将form表单元素的值序列化成对象
function serializeObject(form){ var o={}; $.each(form.serializeArray(),function(index){ if(o[this['n ...
- jquery的attr禁用表单元素的方法
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 获取form表单元素值的4种方式
<html><head><title></title><script type="text/javascript"> f ...
- jQuery name属性与checked属性结合获取表单元素值
var paytype = $("input[name='paytype']:checked").val(); alert(paytype); input元素下名称为paytype ...
- jquery获取表单元素与回显
一.获取哦表单元素 dcoument表单文本对象的集合 all[] 对所有html元素的访问 forms 返回对文档中所有form对象的引用 forms[1] 对所有form对象引用 <scri ...
- jQuery操作Form表单元素
Web开发中常常须要操作表单,form表单元素有select.checkbox.radio.textarea.button.file.text.hidden.password等. 当中checkbox ...
- 遍历form表单里面的表单元素,取其value
form.elements 获取所有表单元素 form 表单 <form action="http://localhost:1995/api/post" class=&quo ...
- jQuery获取Select选择的Text(非表单元素)和 Value(表单元素)(转)
jQuery获取Select选择的Text和Value: 语法解释: . $("#select_id").change(function(){//code...}); //为Sel ...
- jQuery 获取、设置表单元素的值
获取表单元素值: 文本框,文本区域: $("#txt").attr("value"): 多选框 checkbox:$("#checkbox_id&qu ...
随机推荐
- JSP初学者2
<jsp:useBean id="name" class="classname" scope="page|request|session|app ...
- Android 马甲包制作流程
一.马甲包的制作流程 1.配置马甲包的applicationId以及应用名称 在app的build.gradle文件中添加马甲包的配置 android { signingConfigs { confi ...
- Java JSONArray的封装与解析
package com.kigang.test; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import java.ut ...
- Shader Example
//测试viewDir对顶点的影响Shader "Example/TestViewDir" { Properties{ _RimColor("Rim Color" ...
- java面试之----堆(heap)、栈(stack)和方法区(method)
JAVA的JVM的内存可分为3个区:堆(heap).栈(stack)和方法区(method)也叫静态存储区. 堆区: 1.存储的全部是对象,每个对象都包含一个与之对应的class的信息.(class的 ...
- supervisor运行virtualenv环境下的nagios-api
supervisord-example.conf [unix_http_server] file=/tmp/supervisor.sock ; path to your socket file [su ...
- 初见git和github
一.我的github helloworld程序的地址:https://github.com/wyf1213/wyf-project1 二.git/github的相关介绍资料 1.github是什么 ...
- 确定浏览器是否支持某些DOM模块
var supportDOM2Core = document.implementation.hasFeature("Core","2.0"); var supp ...
- application配置和profile隔离配置
前言 github: https://github.com/vergilyn/SpringBootDemo 说明:我代码的结构是用profile来区分/激活要加载的配置,从而在一个project中写各 ...
- 一步一步部署SSIS包图解教程
本文就SQL统计分析SSIS包的部署进行一次详细的部署图解教程,Sql Server Integration Services 提供了非常简单的部署工具,利用这些工具可以方便地将包文件(*.dtsx) ...