2012-07-21 33 views
0

當我真的與JS和jQuery移動:(如何使用jQuery Mobile的

-jquery-1.7.2.js

-jquery.mobile-1.1.1努力得到滑塊的值。 JS

  • 的Chrome版本20.0.1132.57

我的javascript:

<script type="text/javascript" charset="utf-8"> 
$('#temperature').change(function() { 
    alert('.change() called.'); 
}); 
</script> 
</head> 

我的HTML與JQM滑塊:

<div data-role="page" data-theme="a"> 
    <div> 

     <div data-role="header"> 
      <h1>Conditions</h1> 
     </div> 

     <div data-role="fieldcontain"> 
      <label for="temperature">Temperature: </label> <input type="range" 
       name="temperature" id="temperature" value="15" min="-15" max="60" 
       data-highlight="true" /> 
     </div> 
    </div> 
</div> 

-----> My Fiddle

問題1:爲什麼使用jQuery Mobile的,但沒有它的工作,這是不工作,如果?

問題2:從滑塊獲取值的正確方法是什麼?我嘗試了很多,沒有成功。

問題3:爲什麼在小提琴中多次提醒,即使我改變一次值?

問題4:當你在一個頁面上使用實例6滑塊時,獲取值的最佳方式是什麼?

  **EDIT** 

我改成了這樣的了,但同樣的結果:

<script type="text/javascript" charset="utf-8"> 
function valueChanged(){ 
    var SliderValue = $('#temperature').attr('value'); 
    alert("Slider value = " + SliderValue); 
    console.log("SliderValue--->" +SliderValue); 
} 

<div data-role="fieldcontain"> 
      <label for="temperature">Temperature22: </label> <input type="range" 
       name="temperature" id="temperature" value="15" min="-15" max="60" onchange="valueChanged()" 
       data-highlight="true" /> 
     </div> 

並在日誌中我得到:

SliderValue ---> 16 conditions.html:22 SliderValue ---> 41 conditions.html:2 2 SliderValue ---> 41 conditions.html:22 SliderValue ---> 41 conditions.html:22 SliderValue ---> 41 conditions.html:22 SliderValue ---> 41 conditions.html:22 SliderValue- - > 41 conditions.html:22 SliderValue ---> 41 conditions.html:22 SliderValue ---> 41 conditions.html:22 SliderValue ---> 41 conditions.html:22 SliderValue ---> 41 conditions.html:22

因此,它只是無休止地打開警報。奇怪的。

謝謝! 薩米

回答

1

A1:與$('#temperature').attr('value')
A2只要得到它: - >$('#temperature').attr('value')
A3:我不明白這一點不止一次!?
A4:在函數獲取每一個值:

function getTemps(){            
     var temps = new Array[6];  
     temps[0]=$('#temperature1').attr('value'); 
     temps[1]=$('#temperature2').attr('value'); 
     and so on... 
} 

也許幫助:)

+0

謝謝!嘗試將鼠標放在結果窗格上並移動它,並且它始終跳躍。當我在Chrome中嘗試它時,也會發生在真實應用中。你是否試圖爲每個滑塊或每個滑塊使用onchange(「getTemps();」)? – Sami 2012-07-21 15:03:51

+0

如果要在每次更改時將它們保存在數組中,請在每個滑塊上添加「onChange =」getTemps()函數。 – heysamhey 2012-07-21 15:09:36

+0

但我仍然沒有在Mac/Firefox上獲得任何第二次提醒:S – heysamhey 2012-07-21 15:10:02