2014-03-24 26 views
0

我想知道我有两个jQuery脚本。如何访问一个jquery函数中存在的值到另一个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> 

我试图把端值,其通过这样做

变种gauge_value = endValue值是120;

,但是当我在其他脚本提醒它,它提醒未定义

回答

0

我不知道什么是你的问题很明显,但你可以使用

gauge_value = endValue; 

,而不是

var gauge_value = endValue; 

在jQuery中定义一个全局变量

+0

通过这样做,量表米消失。点击时没有任何反应。 – Ali

+0

你在哪里定义endValue? 我的事情endValue是整数,如果你想提醒它,你应该这样做: Alert(endValue.toString()); – SalmanShariati

+0

endValue在脚本中定义为130.我只是想将该值放入我自己的脚本 – Ali

相关问题