Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery Mobile中作为链接的选项值_Javascript_Jquery_Jquery Mobile - Fatal编程技术网

Javascript jQuery Mobile中作为链接的选项值

Javascript jQuery Mobile中作为链接的选项值,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,我正在将选项值实现到一个页面中,我想将其用作导航菜单,并提供指向不同页面的链接。下面的代码确实在页面之间切换,但它会立即将页面返回到index.html。因此,您可以在几秒钟内看到另一个页面,然后返回主页。有什么想法吗 我的代码如下: <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1

我正在将选项值实现到一个页面中,我想将其用作导航菜单,并提供指向不同页面的链接。下面的代码确实在页面之间切换,但它会立即将页面返回到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>

家
家
关于
服务
$(函数(){
//绑定要选择的更改事件
$('#select-custom-1').bind('change',function(){
var url=$(this).val();//获取所选值
if(url){//需要一个url
window.location=url;//重定向
}
返回false;
});
});
主页

关于 家 关于 服务 $(函数(){ //绑定要选择的更改事件 $('#select-custom-1').bind('change',function(){ var url=$(this).val();//获取所选值 if(url){//需要一个url window.location=url;//重定向 } 返回false; }); }); 关于页面

服务 家 关于 服务 $(函数(){ //绑定要选择的更改事件 $('#select-custom-1').bind('change',function(){ var url=$(this).val();//获取所选值 if(url){//需要一个url window.location=url;//重定向 } 返回false; }); }); 服务页面,服务页面

工作示例:

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

非常感谢你,加约特。非常感谢你的帮助!谢谢谢谢谢谢
$.mobile.changePage( url, { transition: "slide", changeHash: false });