• 当 外部 input 值的改变,获取 当前 input type="hidden" 的值


    1.如何用jquery获取<input id="test" name="test" type="text"/>中输入的值?

    方法一:

    $("#test").val()

    方法二:

    $("input[name='test']").val()

    方法三:

    $("input[type='text']").val()

    方法四:

    $("input[type='text']").attr("value")

    2.当 input type="hidden" 的值发生改变时,触发自定事件,获取改变后的值

    demo_1.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <script src="jquery-1.8.2.js"></script>
    </head>
    <body>
      <input type="text" name="current" />
      <input type="hidden" name="hidden" value="0">
    
      <script>
        $("input[type='text']").on('input',function(){
          var currentVal = $("input[type='text']").val();
          // 触发 改变 input type="hidden" 的值
          $("input[type='hidden']").trigger('input:changed', currentVal);
        })
        // 给 input type="hidden" 添加自定义事件
        $("input[type='hidden']").on('input:changed', function (e, val) {
          // 获取 input type="hidden" 的值
            console.log(val);
        });
      </script>
    </body>
    </html>
    

    demo_2.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <script src="jquery-1.8.2.js"></script>
    </head>
    <body>
      <input type="text" name="current" />
      <input type="hidden" name="hidden" onpropertychange="changeVal()" value="0">
    
      <script>
        $("input[type='text']").on('input',function(){
          // 触发绑定方法
          changeVal();
        })
        // 给 input type="hidden" 添加 onpropertychange事件
        function changeVal(){
          // 获取当前值
          console.log($("input[type='hidden']").val()); // 0
        }
      </script>
    </body>
    </html>

    .

  • 相关阅读:
    Mycat的server.xml配置
    Docker构建Mycat(单节点)
    Mycat相关概念解读
    Mycat简介及适用场景
    SpringBoot整合WebService
    SpringBoot事务简单操作及手动回滚
    对事务及其注解@Transactional的解读
    git将某分支的某次提交合并到另一分支
    SpringBoot快速支持国际化i18n
    SpringBoot多数据源自动切换
  • 原文地址:https://www.cnblogs.com/crazycode2/p/8081003.html
Copyright © 2020-2023  润新知