【问题标题】:Set var value from other JavaScript file using jQuery使用 jQuery 从其他 JavaScript 文件设置 var 值
【发布时间】:2012-06-17 10:05:07
【问题描述】:

我有两个 JavaScript 文件:

  1. Main.js
  2. Pmt.js

我也在使用thick box(Ajax 调用)

在 Main.js 中

$(document).ready(function() {

 var cnt=0;

$("#btnPmt").click(function(){
    cnt=cnt+1;
    tb_show('Void Transaction','pmt.jsp?height=310&width=400', null);
});


});

Pmt.js 文件包含在 pmt.jsp 中

<script src="js/Pmt.js" type="text/javascript"></script>

在 Pmt.js 中

 $("#btnPmtClose").click(function(){
    cnt=0;
    parent.tb_remove();
});

我们如何重置 Pmt.js 中的 var cnt 的值,该值在 Main.js 中贴花? 以上不起作用,当我关闭厚盒时,我发现增量值,而不是关闭时设置的零,甚至是 Ajax 调用。

【问题讨论】:

    标签: javascript jquery global-variables reset thickbox


    【解决方案1】:

    在 Main.js 中,通过将 cnt 移到任何函数之外,将其设为 global var:

    var cnt=0;
    $(document).ready(function() {
        ...
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-13
      • 2015-03-04
      • 2012-08-10
      • 2015-04-04
      • 2018-03-07
      • 2015-09-12
      • 2010-10-11
      • 1970-01-01
      相关资源
      最近更新 更多