如何将一个jquery函数中存在的值访问到另一个jquery函数中?

时间:2014-03-24 10:49:51

标签: jquery html jqwidget

我想知道我有两个jquery脚本。

1-一个仪表(使用jqwidgets.com库)

2-我自己定义的脚本

仪表仪表基本上是我正在使用的小部件。现在我想访问仪表的值。如果抄表是,让我们假设为10,那么我希望在我自己定义的脚本中可以访问该10个值,以便我可以在任何地方使用它,无论出于何种目的。 这是html代码。

  <div class="demo-gauge" style="position: relative;height: 200px;margin-left:2.5em;">

     <div id='gauge' style="position: absolute; top: 0px; left: 0px;">
           </div>
         <div id='slider' style="position: absolute; top: 160px; left: 5px">
              </div>
  </div>

和仪表的脚本。我的脚本只会得到价值,并且此刻只是提醒它。

<script type="text/javascript">
   var gauge_value = endValue;


$(document).ready(function () {         
            $('#gauge').jqxGauge({
                ranges: [{ startValue: 0, endValue: 130, style: { fill: '#4cb848', stroke: '#4cb848' }, startDistance: 0, endDistance: 0 },
                         { startValue: 130, endValue: 180, style: { fill: '#fad00b', stroke: '#fad00b' }, startDistance: 0, endDistance: 0 },
                         { startValue: 180, endValue: 220, style: { fill: '#e53d37', stroke: '#e53d37' }, startDistance: 0, endDistance: 0}],
                cap: { size: '5%', style: { fill: '#2e79bb', stroke: '#2e79bb'} },
                border: { style: { fill: '#8e9495', stroke: '#7b8384', 'stroke-width': 0 } },
                ticksMinor: { interval: 0, size: '5%' },
                ticksMajor: { interval: 0, size: '10%' },       
                labels: { position: 'outside', interval: 60 },
                pointer: { style: { fill: '#2e79bb' }, width: 5 },
                animationDuration: 1500
            });
            $('#slider').jqxSlider({ min: 0, max: 220, mode: 'fixed', ticksFrequency: 20, width: 150, value: 120,  showButtons: true });

            $('#slider').mousedown(function () {
                $('#gauge').jqxGauge('value', $('#slider').jqxSlider('value'));
            });
            $('#slider').on('slideEnd', function (e) {
                $('#gauge').jqxGauge('value', e.args.value);
            });
            $('#slider').on('mousewheel', function () {
                $('#gauge').jqxGauge('value', $('#slider').jqxSlider('value'));
            });
            $('#gauge').jqxGauge('value', 120);
        });
    </script>

我试图通过这样做把结束值设为120

var gauge_value = endValue;

但是当我在另一个脚本中提醒它时,它会发出未定义的警告

1 个答案:

答案 0 :(得分:0)

我不明白你的问题是什么,但你可以使用

gauge_value = endValue;

而不是

var gauge_value = endValue;

在jQuery中定义全局变量