在javascript文件之外定义的全局变量不起作用

时间:2016-06-29 09:20:11

标签: javascript global-variables

我有一个html文件:

<body>
  <?php 
    $rand1 = rand(0,10);
    $rand2 = rand(0,20);
  ?>

  <span id="client-registration-button">Registration</span>

  <script>var checksum = <?php echo $rand1+$rand2; ?>;</script>
  <script src="/main.js"></script>
</body>

在main.js中是:

$('#client-registration-button').click(function() {         
    alert(checksum);    
});

但是警报没有显示任何值,只是空警报窗口。为什么全局变量没有价值&#34;校验和&#34;显示?

0 个答案:

没有答案
相关问题