Passsing slider values between pages in JQuery Mobile

回眸只為那壹抹淺笑 提交于 2019-12-06 06:03:22

I played around with your example and got it working. I used this info from the docu

Form buttons

For ease of styling, the framework automatically converts any button or input element with a type of submit, reset, or button into a custom styled button — there is no need to add the data-role="button" attribute. However, if needed, you can directly call the button plugin on any selector, just like any jQuery plugin:

 $('[type="submit"]').button();

which results in this script

<script>
    $('[type="submit"]').bind( "click", function() {
      first_count = $('#first_slider').val();
      second_count = $('#second_slider').val();
      $('#first_count').text('' + first_count);
      $('#second_count').text('' + second_count);
      $.mobile.changePage('#front');
      return false;
    });
</script>

complete corrected version of your example:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Multi-page template</title>
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
  <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
  <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>

<body>
  <div data-role="page" id="review" data-theme="a">
    <div data-role="header">
      <h1>Review</h1>
    </div>
    <p>
      Review content
    </p>

    <div data-role="content" data-theme="a">
      <form>
        <label for="first_slider">First:</label>
        <input type="range" id="first_slider" value="60" min="0" max="100" />
        <label for="second_slider">Second:</label>
        <input type="range" id="second_slider" value="60" min="0" max="100" />
        <input type="submit" value="Submit" />
      </form>
    </div>
  </div>

  <!-- ======================== -->
  <div data-role="page" id="front" data-theme="a">
    <div data-role="header">
      <h1>Front</h1>
    </div>

    <div data-role="content" data-theme="a">
      <p>
        Front content
      </p>

      <p id='first_count'></p>
      <p id='second_count'></p>

      <p>
        <a href="#review" data-role="button">Main</a>
      </p>
    </div>

    <script>
      $(document).bind('pageinit');
    </script>
  </div>

  <script>
    $('[type="submit"]').bind( "click", function() {
      first_count = $('#first_slider').val();
      second_count = $('#second_slider').val();
      $('#first_count').text('' + first_count);
      $('#second_count').text('' + second_count);
      $.mobile.changePage('#front');
      return false;
    });
  </script>
</body>
</html>

screenshot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!