jQuery Mobile:如何获取Range Slider的change事件? [英] jQuery Mobile: how to get the change event of a range Slider?

查看:63
本文介绍了jQuery Mobile:如何获取Range Slider的change事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的事情就像代码一样:当该值大于10时,显示> 10或显示1-10.它可以正常工作.但是,如果我取消注释jquery mobile,它将不再起作用.

What I am trying to do is just like the code: when the value is greater than 10, display >10, or display 1 - 10. It works fine. However, if I uncomment the jquery mobile , it does not work anymore.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 
<!--<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>-->

</head>
<body>
<form>
<label for='range'>as</label>
<input id='range' type='range' onmousemove='test()'>
<p id='display'>display</p>
</form>
<script>
function test(){
  var v = $('#range').val();
  if(v <= 10)$("#display").text('1-10');
  else $("#display").text('>10');
}
</script>
</body>
</html>

推荐答案

在小部件初始化之后,有三个JQM滑块事件可用:

There are three JQM slider events available after widget initialization:

  • slidestart
  • 更改
  • slidestop

要获得正确的行为,您应该提供正确的JQM页面结构并在pagecreate事件中注册事件处理程序.下面是一个简单的存根,您可以在其中测试JQM滑块:

To get the correct behavior, you should provide the correct JQM page structure and register the event handlers inside the pagecreate event. Below is a simple stub where you can test a JQM slider:

$(document).on("pagecreate", "#page-one", function() {
  $("#slider").on("slidestart", function() {
    var val = $(this).val();
    $("#txt1").val(val);
  });
  $("#slider").on("change", function() {
    var val = $(this).val();
    $("#txt2").val(val);
  });
  $("#slider").on("slidestop", function() {
    var val = $(this).val();
    $("#txt3").val(val);
  });
});

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.css">
  <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
</head>
<body>
  <div id="page-one" data-role="page">
    <div role="main" class="ui-content">
      <label for="slider">Slider</label>
      <input type="range" name="slider" id="slider" min="1" max="100" value="1" step="1" autocomplete="off" />
        <fieldset class="ui-grid-b">
          <div class="ui-block-a">
            <label for="txt1">slidestart:</label>
            <input data-mini="true" name="txt1" id="txt1" value="" type="text">
          </div>
          <div class="ui-block-b">
            <label for="txt2">slidechange:</label>
            <input data-mini="true" name="txt2" id="txt2" value="" type="text">
          </div>
          <div class="ui-block-c">
            <label for="txt3">slidestop:</label>
            <input data-mini="true" name="txt3" id="txt3" value="" type="text">
          </div>
        </fieldset>
    </div>
  </div>
</body>
</html>

这篇关于jQuery Mobile:如何获取Range Slider的change事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆