2014-03-24 27 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

相關問題