选项值作为jQuery Mobile中的链接

用户名

我正在将选项值实现到页面中,并且希望将其用作具有指向不同页面的链接的导航菜单。下面的代码在页面之间进行切换,但是它立即将页面返回给index.html。结果,您可以在不到一秒钟的时间内看到另一个页面,然后返回到主页。有什么想法吗?

我的代码如下:

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<!-- Start of index page -->
    <div data-role="page" data-theme="b" id="index">
        <div data-role="header" data-position="inline">
            <h1>HOME</h1>
        </div><!-- /header -->
<div class="ui-field-contain">
    <label for="select-custom-1"></label>
    <select name="select-custom-1" id="select-custom-1" data-native-menu="false">
        <option value="index.html">HOME</option>
        <option value="#about">ABOUT</option>
        <option value="#services">SERVICES</option>
    </select>
    <script>
    $(function(){
      // bind change event to select
      $('#select-custom-1').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              window.location = url; // redirect
          }
          return false;
      });
    });
</script>
</div>
        <div data-role="content" data-theme="b">
        <p>Home Page</p>
        </div><!-- /content -->
        <div data-role="footer" data-theme="b">
        </div><!-- /footer -->
    </div><!-- /index page -->

<!-- Start of about page -->
    <div data-role="page" data-theme="b" id="about">
        <div data-role="header" data-position="inline">
            <h1>ABOUT</h1>
        </div><!-- /header -->
<div class="ui-field-contain">
    <label for="select-custom-1"></label>
    <select name="select-custom-1" id="select-custom-1" data-native-menu="false">
        <option value="index.html">HOME</option>
        <option value="#about">ABOUT</option>
        <option value="#services">SERVICES</option>
    </select>
    <script>
    $(function(){
      // bind change event to select
      $('#select-custom-1').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              window.location = url; // redirect
          }
          return false;
      });
    });
</script>
</div>
        <div data-role="content" data-theme="b">
        <p>About Page</p>
        </div><!-- /content -->
        <div data-role="footer" data-theme="b">
        </div><!-- /footer -->
    </div><!-- /about page -->

    <!-- Start of services page -->
    <div data-role="page" data-theme="b" id="services">
        <div data-role="header" data-position="inline">
            <h1>SERVICES</h1>
        </div><!-- /header -->
<div class="ui-field-contain">
    <label for="select-custom-1"></label>
    <select name="select-custom-1" id="select-custom-1" data-native-menu="false">
        <option value="index.html">HOME</option>
        <option value="#about">ABOUT</option>
        <option value="#services">SERVICES</option>
    </select>
    <script>
    $(function(){
      // bind change event to select
      $('#select-custom-1').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              window.location = url; // redirect
          }
          return false;
      });
    });
</script>
</div>
        <div data-role="content" data-theme="b">
        <p>Services Page, Services Page</p>
        </div><!-- /content -->
        <div data-role="footer" data-theme="b">
        </div><!-- /footer -->
    </div><!-- /services page -->

</body>
</html>
Gajotres

工作示例:

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</head>
<body>
<!-- Start of index page -->
    <div data-role="page" data-theme="b" id="index">
        <div data-role="header" data-position="inline">
            <h1>HOME</h1>
        </div><!-- /header -->
<div class="ui-field-contain">
    <label for="select-custom-1"></label>
    <select name="select-custom-1" id="select-custom-1" data-native-menu="false">
        <option value="index.html">HOME</option>
        <option value="#about">ABOUT</option>
        <option value="#services">SERVICES</option>
    </select>
    <script>
    $(function(){
      // bind change event to select
      $('#select-custom-1').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              $.mobile.changePage( url, { transition: "slide", changeHash: false });
          }
          return false;
      });
    });
</script>
</div>
        <div data-role="content" data-theme="b">
        <p>Home Page</p>
        </div><!-- /content -->
        <div data-role="footer" data-theme="b">
        </div><!-- /footer -->
    </div><!-- /index page -->

<!-- Start of about page -->
    <div data-role="page" data-theme="b" id="about">
        <div data-role="header" data-position="inline">
            <h1>ABOUT</h1>
        </div><!-- /header -->
<div class="ui-field-contain">
    <label for="select-custom-1"></label>
    <select name="select-custom-1" id="select-custom-1" data-native-menu="false">
        <option value="index.html">HOME</option>
        <option value="#about">ABOUT</option>
        <option value="#services">SERVICES</option>
    </select>
    <script>
    $(function(){
      // bind change event to select
      $('#select-custom-1').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              $.mobile.changePage( url, { transition: "slide", changeHash: false });
          }
          return false;
      });
    });
</script>
</div>
        <div data-role="content" data-theme="b">
        <p>About Page</p>
        </div><!-- /content -->
        <div data-role="footer" data-theme="b">
        </div><!-- /footer -->
    </div><!-- /about page -->

    <!-- Start of services page -->
    <div data-role="page" data-theme="b" id="services">
        <div data-role="header" data-position="inline">
            <h1>SERVICES</h1>
        </div><!-- /header -->
<div class="ui-field-contain">
    <label for="select-custom-1"></label>
    <select name="select-custom-1" id="select-custom-1" data-native-menu="false">
        <option value="index.html">HOME</option>
        <option value="#about">ABOUT</option>
        <option value="#services">SERVICES</option>
    </select>
    <script>
    $(function(){
      // bind change event to select
      $('#select-custom-1').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              $.mobile.changePage( url, { transition: "slide", changeHash: false });
          }
          return false;
      });
    });
</script>
</div>
        <div data-role="content" data-theme="b">
        <p>Services Page, Services Page</p>
        </div><!-- /content -->
        <div data-role="footer" data-theme="b">
        </div><!-- /footer -->
    </div><!-- /services page -->

</body>
</html>

您需要使用jQuery Mobile解决方案进行页面遍历:

$.mobile.changePage( url, { transition: "slide", changeHash: false });

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何从另一个文件中加载数据作为JavaScript / jQuery中的选项值?

来自分类Dev

否则值作为Pyspark中的选项

来自分类Dev

如何链接到JQuery Mobile中的特定标签页?

来自分类Dev

如何在jQuery Mobile中设置“列表项>链接”的样式

来自分类Dev

如何-动态-更改jQuery Mobile中的链接文本颜色?

来自分类Dev

如何在jquery mobile中设置“列表项>链接”的样式

来自分类Dev

使jQuery UI Slider值作为链接工作

来自分类Dev

Jquery Mobile中的select选项中的问题

来自分类Dev

jQuery无法设置选项列表中的值

来自分类Dev

jquery 插件选项中的布尔值

来自分类Dev

在选项标签值中链接页面

来自分类Dev

传递多维数组元素id作为jquery函数中的选项

来自分类Dev

如何执行在Jquery插件中作为选项传递的函数?

来自分类Dev

jQuery值作为html中的id传递

来自分类Dev

jQuery值作为html中的id传递

来自分类Dev

使用Cordova / jQuery-mobile在外部设备浏览器中打开链接

来自分类Dev

如何在JQuery Mobile中获取内部页面链接的查询参数

来自分类Dev

使用JQuery Mobile向上或向下移动控件组中的多个链接

来自分类Dev

在带有phonegap的jQuery mobile中链接页面/加载javascript的最佳实践是什么?

来自分类Dev

jQuery Mobile App-将Navbar链接中的href属性更新为“未定义”

来自分类Dev

将.CSS样式元素添加到JQuery Mobile中的链接按钮

来自分类Dev

使用JQuery Mobile向上或向下移动控件组中的多个链接

来自分类Dev

如何在JQuery Mobile中获取内部页面链接的查询参数

来自分类Dev

jQuery Mobile锚链接不起作用

来自分类Dev

jQuery Mobile无法从内部链接过渡

来自分类Dev

如何使用HTML5,JQuery mobile ..中的链接在同一Page内进行内部导航?

来自分类Dev

在jQuery Mobile中获取PHP会话值

来自分类Dev

如何使用jquery在选择选项中设置选择的值?

来自分类Dev

在选择多个jQuery中获取禁用选项的值

Related 相关文章

  1. 1

    如何从另一个文件中加载数据作为JavaScript / jQuery中的选项值?

  2. 2

    否则值作为Pyspark中的选项

  3. 3

    如何链接到JQuery Mobile中的特定标签页?

  4. 4

    如何在jQuery Mobile中设置“列表项>链接”的样式

  5. 5

    如何-动态-更改jQuery Mobile中的链接文本颜色?

  6. 6

    如何在jquery mobile中设置“列表项>链接”的样式

  7. 7

    使jQuery UI Slider值作为链接工作

  8. 8

    Jquery Mobile中的select选项中的问题

  9. 9

    jQuery无法设置选项列表中的值

  10. 10

    jquery 插件选项中的布尔值

  11. 11

    在选项标签值中链接页面

  12. 12

    传递多维数组元素id作为jquery函数中的选项

  13. 13

    如何执行在Jquery插件中作为选项传递的函数?

  14. 14

    jQuery值作为html中的id传递

  15. 15

    jQuery值作为html中的id传递

  16. 16

    使用Cordova / jQuery-mobile在外部设备浏览器中打开链接

  17. 17

    如何在JQuery Mobile中获取内部页面链接的查询参数

  18. 18

    使用JQuery Mobile向上或向下移动控件组中的多个链接

  19. 19

    在带有phonegap的jQuery mobile中链接页面/加载javascript的最佳实践是什么?

  20. 20

    jQuery Mobile App-将Navbar链接中的href属性更新为“未定义”

  21. 21

    将.CSS样式元素添加到JQuery Mobile中的链接按钮

  22. 22

    使用JQuery Mobile向上或向下移动控件组中的多个链接

  23. 23

    如何在JQuery Mobile中获取内部页面链接的查询参数

  24. 24

    jQuery Mobile锚链接不起作用

  25. 25

    jQuery Mobile无法从内部链接过渡

  26. 26

    如何使用HTML5,JQuery mobile ..中的链接在同一Page内进行内部导航?

  27. 27

    在jQuery Mobile中获取PHP会话值

  28. 28

    如何使用jquery在选择选项中设置选择的值?

  29. 29

    在选择多个jQuery中获取禁用选项的值

热门标签

归档