1. <tfoot id='5CXlg'></tfoot>

    <legend id='5CXlg'><style id='5CXlg'><dir id='5CXlg'><q id='5CXlg'></q></dir></style></legend>
    1. <small id='5CXlg'></small><noframes id='5CXlg'>

      • <bdo id='5CXlg'></bdo><ul id='5CXlg'></ul>
    2. <i id='5CXlg'><tr id='5CXlg'><dt id='5CXlg'><q id='5CXlg'><span id='5CXlg'><b id='5CXlg'><form id='5CXlg'><ins id='5CXlg'></ins><ul id='5CXlg'></ul><sub id='5CXlg'></sub></form><legend id='5CXlg'></legend><bdo id='5CXlg'><pre id='5CXlg'><center id='5CXlg'></center></pre></bdo></b><th id='5CXlg'></th></span></q></dt></tr></i><div id='5CXlg'><tfoot id='5CXlg'></tfoot><dl id='5CXlg'><fieldset id='5CXlg'></fieldset></dl></div>

      在 jQuery 中绑定现有的 JavaScript 函数

      时间:2023-09-04

    3. <i id='k5zxD'><tr id='k5zxD'><dt id='k5zxD'><q id='k5zxD'><span id='k5zxD'><b id='k5zxD'><form id='k5zxD'><ins id='k5zxD'></ins><ul id='k5zxD'></ul><sub id='k5zxD'></sub></form><legend id='k5zxD'></legend><bdo id='k5zxD'><pre id='k5zxD'><center id='k5zxD'></center></pre></bdo></b><th id='k5zxD'></th></span></q></dt></tr></i><div id='k5zxD'><tfoot id='k5zxD'></tfoot><dl id='k5zxD'><fieldset id='k5zxD'></fieldset></dl></div>
        <legend id='k5zxD'><style id='k5zxD'><dir id='k5zxD'><q id='k5zxD'></q></dir></style></legend>
        <tfoot id='k5zxD'></tfoot>
            <tbody id='k5zxD'></tbody>
          • <bdo id='k5zxD'></bdo><ul id='k5zxD'></ul>

              <small id='k5zxD'></small><noframes id='k5zxD'>

                本文介绍了在 jQuery 中绑定现有的 JavaScript 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                使用 jQuery 我想将现有函数绑定到按钮.我浏览了文档并找到了 bind 方法,但是 jQuery 站点上的示例绑定了新创建的函数,因为我想绑定一个已经定义的函数,例如:

                Using jQuery I want to bind an existing function to a button. I've been through the documentation and have found the bind method but the examples on the jQuery site bind newly created functions where as I want to bind a function that's already defined, e.g:

                function fHardCodedFunction(){
                   //Do stuff
                }
                
                function fBindFunctionToElement(){
                   $("#MyButton").bind("click", fHardCodedFunction());
                }
                

                这可能吗?还是我走错了路?

                Is this possible? Or am I going about this the wrong way?

                推荐答案

                普通的 fHardCodedFunction 已经引用了函数,后缀 () 只会调用它.所以只需传递函数而不是调用它,从而传递返回值:

                The plain fHardCodedFunction already refers to the function and the suffix () will just call it. So just pass the function instead of calling it and thereby just passing the return value:

                function fBindFunctionToElement(){
                   $("#MyButton").bind("click", fHardCodedFunction);
                }
                

                这篇关于在 jQuery 中绑定现有的 JavaScript 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 jQuery 监听 keydown 事件 下一篇:用于编辑谷歌地图折线的事件处理程序?

                相关文章

                最新文章

              • <legend id='0akx6'><style id='0akx6'><dir id='0akx6'><q id='0akx6'></q></dir></style></legend>

                1. <i id='0akx6'><tr id='0akx6'><dt id='0akx6'><q id='0akx6'><span id='0akx6'><b id='0akx6'><form id='0akx6'><ins id='0akx6'></ins><ul id='0akx6'></ul><sub id='0akx6'></sub></form><legend id='0akx6'></legend><bdo id='0akx6'><pre id='0akx6'><center id='0akx6'></center></pre></bdo></b><th id='0akx6'></th></span></q></dt></tr></i><div id='0akx6'><tfoot id='0akx6'></tfoot><dl id='0akx6'><fieldset id='0akx6'></fieldset></dl></div>

                      <bdo id='0akx6'></bdo><ul id='0akx6'></ul>

                  1. <small id='0akx6'></small><noframes id='0akx6'>

                    <tfoot id='0akx6'></tfoot>