//html
<input type="text" id="input-1" />

// js
<script>
    +function ($) {
        function testEvent() {//第 二步 click  导致 本函数执行
            var hidden = jQuery.Event("hide.bs", {//第 二步 (1)为event添加额外参数
                user: "foo",
                pass: "bar",
                relatedTarget: $("#input-1")[0]
            });
            $("#input-1").trigger(hidden);//第 二步 (2) 派发自定义事件
        }

        $("#input-1").on("click", testEvent);//第一步 普通注册 click监听
    }(jQuery)
    $(function () {
        $("#input-1").on("hide.bs", function (event) {//第 三 步 注册事件,(上面派发后 本函数执行)
            alert(event.relatedTarget.tagName)//INPOUT
            alert(event.user)//foo
        })
    })

</script>

 

相关文章:

  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-01
  • 2021-12-13
  • 2022-03-06
  • 2021-10-31
  • 2021-09-04
  • 2022-12-23
相关资源
相似解决方案