小麦加油呀 2016-11-07 06:01 采纳率: 100%
浏览 5701
已采纳

如何获取form表单对象的值

姓名:
电话:
    我页面中有这样多个表单,我都是这个定义的,当我点击确定按钮时,此时能够获得相对应的表单对象,我该怎么获取到他的两个值呢?
  • 写回答

7条回答 默认 最新

  • 陈田田 2016-11-07 07:06
    关注

    你是不是这样写的:

    
    <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方法:

    
    $(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);
            });
         });
    })
    



    以上是来自tity的回答,希望对你有所帮助。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

问题事件

  • 已采纳回答 8月8日

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?