• 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);
            });
         });
    })
    

      

  • 相关阅读:
    整理SVN代码-->正式环境的代码
    业务(1)
    在一个项目中跨领域调用接口的的实现
    一个java文件编译之后会产生多个class文件
    shutil模块
    shevle模块
    confiparser模块
    sys模块
    subprocess模块
    【ADO.NET】3、从TXT中导入数据到数据库
  • 原文地址:https://www.cnblogs.com/qqblog/p/6586298.html
Copyright © 2020-2023  润新知