2015-12-15 59 views
0

我在右上角创建了一个下拉列表,列出用户登录网站时的各种选项。目前要显示每个网页右上角的下拉列表,我在每个HTML文件中编写HTML代码。从多个HTML文件访问单个下拉列表

我试图实现一个系统,我可以从网站中的每个HTMl网页调用此代码,并且在单个文件中进行的更改应用于所有网页..我无法弄清楚如何实现它..Please帮助... HTML代码

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta name="google-signin-scope" content="profile email"> 
    <meta name="google-signin-client_id" content="909447696017-ka0dc75ts261cua6d2ho5mvb7uuo9njc.apps.googleusercontent.com"> 
    <script src="https://apis.google.com/js/platform.js" async defer></script> 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
    <title>My Friends</title> 
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script src="js/jquery-1.11.3.min.js"></script> 
    <!-- Bootstrap --> 
    <link href="css/bootstrap.min.css" rel="stylesheet"> 
    <link href="css/mystore.css" rel="stylesheet"> 
    <link href='http://fonts.googleapis.com/css?family=Happy+Monkey' rel='stylesheet' type='text/css'> 
</head> 
<body> 
    <div id="main"> 
     <div class="collapse navbar-collapse" id="myNavbar1"> 
      <ul class="nav navbar-nav navbar-right" id="navbar1right"> 
       <li class="dropdown" id="subheader"> 
        <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> 
         <span id="salutation"></span> <span class="caret"> </span> 
        </a> 
        <ul class="dropdown-menu"> 
         <li><a href="postings.html"><span class="glyphicon glyphicon-phone"></span>Postings </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="wishlists.html"><span class="glyphicon glyphicon-heart-empty"></span>WishList </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="incomingrequests.html"><span class="glyphicon glyphicon-inbox"></span>Incoming Requests </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="leasedoutitems.html"><span class="glyphicon glyphicon-gift"></span>Leased Out Items </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="leasedinitems.html"><span class="glyphicon glyphicon-shopping-cart"></span>Leased In Items </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="friendslist.html"><span class="glyphicon glyphicon-user"></span>Friends </a></li> 
         <li role="separator" class="divider"></li> 
         <li id="logoutoptionmenu"><a href="#"><span class="glyphicon glyphicon-log-out"></span> Logout </a></li> 
        </ul> 
       </li> 
      </ul> 
     </div> 
    </div> 
    <!-- Include all compiled plugins (below), or include individual files as needed --> 
    <script src="js/bootstrap.min.js"></script> 
</body> 
</html> 

它是如何看起来UI屏幕截图..

Drop Down List

EDIT 1:

作为由用户@ DelightedD0D我除去无序列表代码中提到并在同一文件夹中的HTML文件在一个单独的文件。公司加入。我在我的身体标记相应的编辑的代码,并添加下面的jQuery代码在头部分

 $(function(){ 
     $.get("menu.inc", function(response) { 
       $('#myNavbar1').html(response); 
       applyDynamicBindings('#myNavbar1'); 
     }); 
    }); 

    function applyDynamicBindings(container_selector){ 
     var $container=$(container_selector); 
     $container.find("ul").click(function(){ 
      alert('triggered function bound to dynamic element'); 
     }); 
    } 

莫名其妙的代码是不是能够进入get方法作为警报里面是没有得到显示它。即使按钮没有在浏览器中显示。

+0

如何用户nevigate您页/ –

+0

通过链接,其中有些是与显示在下拉列表中... – Lucy

回答

1

你可以使用一个简单的模板。编写HTML为您的菜单并将其保存在一个名为menu.inc一个单独的文件(使用任何你想要的非标准扩展名)然后调用下面你需要的菜单出现在任何网页上:

$.get('path_to/menu.inc', function(response) { 
     $('#myNavbar1').html(response); 
}); 

现在,如果你曾经需要编辑菜单,您可以在一个地方执行此操作,并且这些更改会自动影响包括所有页面在内的所有内容。


在页面

所以做这样的事情:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta name="google-signin-scope" content="profile email"> 
    <meta name="google-signin-client_id" content="909447696017-ka0dc75ts261cua6d2ho5mvb7uuo9njc.apps.googleusercontent.com"> 
    <script src="https://apis.google.com/js/platform.js" async defer></script> 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
    <title>My Friends</title> 
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
    <script src="js/jquery-1.11.3.min.js"></script> 
    <!-- Bootstrap --> 
    <link href="css/bootstrap.min.css" rel="stylesheet"> 
    <link href="css/mystore.css" rel="stylesheet"> 
    <link href='http://fonts.googleapis.com/css?family=Happy+Monkey' rel='stylesheet' type='text/css'> 
    <script> 
     $(function(){ 
      $.get('path_to/menu.inc', function(response) { 
        $('#myNavbar1').html(response); 
        applyDynamicBindings('#myNavbar1'); 
      }); 
     }); 
     function applyDynamicBindings(container_selector){ 
      var $container=$(container_selector); 
      $container.find('.some-menu-item').click(function(){ 
       alert('triggered function bound to dynamic element'); 
      }); 
     } 

    </script> 
</head> 
<body> 
    <div id="main"> 
     <div class="collapse navbar-collapse" id="myNavbar1"> 
     </div> 
    </div> 
    <!-- Include all compiled plugins (below), or include individual files as needed --> 
    <script src="js/bootstrap.min.js"></script> 
</body> 
</html> 

menu.inc刚才这样的:

  <ul class="nav navbar-nav navbar-right" id="navbar1right"> 
       <li class="dropdown" id="subheader"> 
        <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> 
         <span id="salutation"></span> <span class="caret"> </span> 
        </a> 
        <ul class="dropdown-menu"> 
         <li><a href="postings.html"><span class="glyphicon glyphicon-phone"></span>Postings </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="wishlists.html"><span class="glyphicon glyphicon-heart-empty"></span>WishList </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="incomingrequests.html"><span class="glyphicon glyphicon-inbox"></span>Incoming Requests </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="leasedoutitems.html"><span class="glyphicon glyphicon-gift"></span>Leased Out Items </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="leasedinitems.html"><span class="glyphicon glyphicon-shopping-cart"></span>Leased In Items </a></li> 
         <li role="separator" class="divider"></li> 
         <li><a href="friendslist.html"><span class="glyphicon glyphicon-user"></span>Friends </a></li> 
         <li role="separator" class="divider"></li> 
         <li id="logoutoptionmenu"><a href="#"><span class="glyphicon glyphicon-log-out"></span> Logout </a></li> 
        </ul> 
       </li> 
      </ul> 
+0

或类似的解决方案在这里找到http://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file – Bindrid

+0

@ DelightedD0D我是否需要只复制身体标记内的代码或头标记中的代码? – Lucy

+0

只是你的菜单本身的代码。虐待更新 – DelightedD0D