我真的在 js 和 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>
我的带有 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>
问题 1:如果使用 jquery Mobile 但没有它,为什么这不起作用?
问题2:从滑块获取值的正确方法是什么?我尝试了很多,没有成功。
问题3:为什么即使我更改了一次值,Fiddle 也会多次发出警报?
问题 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: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 条件.html:22 SliderValue--->41 条件.html:22
所以它只是无休止地打开警报。诡异的。
谢谢!萨米人