使用Jquery Mobile时如何从滑块获取值

时间:2012-07-21 14:44:40

标签: jquery jquery-mobile slider

我真的在与js和Jquery手机挣扎:(

-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>

我的带jqm滑块的html:

<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 ---&gt; 16 conditions.html:22 SliderValue ---&gt; 41   conditions.html:22 SliderValue ---&gt; 41 conditions.html:22   SliderValue ---&gt; 41 conditions.html:22 SliderValue ---&gt; 41   conditions.html:22 SliderValue ---&gt; 41 conditions.html:22   SliderValue ---&gt; 41 conditions.html:22 SliderValue ---&gt; 41   conditions.html:22 SliderValue ---&gt; 41 conditions.html:22   SliderValue ---&gt; 41 conditions.html:22 SliderValue ---&gt; 41   conditions.html:22

所以它只是无休止地打开警报。怪异。

谢谢! 萨米

1 个答案:

答案 0 :(得分:1)

A1:用$('#temperature').attr('value')来获取它 A2: - &gt; $('#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...
}

也许这会有所帮助:)

相关问题