【问题标题】:Call in a function another function JQuery在一个函数中调用另一个函数 JQuery
【发布时间】:2013-12-17 03:49:05
【问题描述】:

我有两个 JQuery 函数,我需要在一个函数中启动其中一个。这是我的例子:

<script type="text/javascript">
$(document).ready(function aa() {...... })
</script>

我想在另一个中调用这个函数:

<script type="text/javascript">
  function hello(){
    aa();
  }
</script>

【问题讨论】:

  • 这就像大海捞针 :D 请清理你的代码,尽量只暴露最有趣的部分,并在代码和解释之间找到一个很好的平衡。
  • -1 因为没看懂题目,看了题目还是没看懂题目和题目。
  • 我编辑了我的问题!现在不是 -1 ;)
  • 感谢您整理,谢谢

标签: javascript jquery html ajax


【解决方案1】:

aa 无法访问,因为您在 $(document) 中定义了它。准备好,尝试将其放入 global scope

function aa() {
   ...
}

$(document).ready(aa);

在你的其他脚本中你可以这样称呼它

 function hello(){
   aa();
 }

【讨论】:

    【解决方案2】:

    需要进行一点重组才能将 aa 从代码顶部的 $(document).ready 中移出,以便您也可以在其他地方使用它

    /* call aa as ready handler*/
    $(document).ready(aa);
    /* aa now global*/
    function aa() {
        $('#catAssociate tbody tr').contextMenu('myMenu2', {
            bindings: {
                'open': function (t) {
                    console.log("chiamo ioooo");
                    DeleteAction(t, "Open");
                },
            }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 2017-03-07
      • 1970-01-01
      • 2013-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多