<small id='cXvzz'></small><noframes id='cXvzz'>

<tfoot id='cXvzz'></tfoot>
  • <legend id='cXvzz'><style id='cXvzz'><dir id='cXvzz'><q id='cXvzz'></q></dir></style></legend>
    <i id='cXvzz'><tr id='cXvzz'><dt id='cXvzz'><q id='cXvzz'><span id='cXvzz'><b id='cXvzz'><form id='cXvzz'><ins id='cXvzz'></ins><ul id='cXvzz'></ul><sub id='cXvzz'></sub></form><legend id='cXvzz'></legend><bdo id='cXvzz'><pre id='cXvzz'><center id='cXvzz'></center></pre></bdo></b><th id='cXvzz'></th></span></q></dt></tr></i><div id='cXvzz'><tfoot id='cXvzz'></tfoot><dl id='cXvzz'><fieldset id='cXvzz'></fieldset></dl></div>
    • <bdo id='cXvzz'></bdo><ul id='cXvzz'></ul>

      1. 将特定的类/ID 应用于菜单上的当前页面 (PHP)

        Apply a specific class/id to current page on menu (PHP)(将特定的类/ID 应用于菜单上的当前页面 (PHP))

          1. <small id='RY1yD'></small><noframes id='RY1yD'>

            <i id='RY1yD'><tr id='RY1yD'><dt id='RY1yD'><q id='RY1yD'><span id='RY1yD'><b id='RY1yD'><form id='RY1yD'><ins id='RY1yD'></ins><ul id='RY1yD'></ul><sub id='RY1yD'></sub></form><legend id='RY1yD'></legend><bdo id='RY1yD'><pre id='RY1yD'><center id='RY1yD'></center></pre></bdo></b><th id='RY1yD'></th></span></q></dt></tr></i><div id='RY1yD'><tfoot id='RY1yD'></tfoot><dl id='RY1yD'><fieldset id='RY1yD'></fieldset></dl></div>
                <tbody id='RY1yD'></tbody>
                <bdo id='RY1yD'></bdo><ul id='RY1yD'></ul>
                  <legend id='RY1yD'><style id='RY1yD'><dir id='RY1yD'><q id='RY1yD'></q></dir></style></legend>
                  <tfoot id='RY1yD'></tfoot>

                  本文介绍了将特定的类/ID 应用于菜单上的当前页面 (PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个这样的菜单:

                  <a href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a><a href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a><a href="http://domain.com/folder/gallery"><img style="blahblah" src="blahblahblahblah"></a><a href="http://domain.com/folder/dontknow"><img style="blahblah" src="blahblahblahblah"></a>

                  我想要一些可以自动将 class="current" 添加到我当前所在页面的内容.链接(如您在上面的代码中所见)类似于 domain.com/folder/biography 或 domain.com/folder/contacts,所以没有 .php/.html 等

                  我尝试过:

                  <a <?php if (strpos($_SERVER['PHP_SELF'], 'biography')) echo 'class="current"';?>href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a><a <?php if (strpos($_SERVER['PHP_SELF'], 'contacts')) echo 'class="current"';?>href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>......

                  但它不起作用......带strops的解决方案似乎可行,可能我做错了......:P

                  解决方案

                  你应该:

                  1. !== false 检查 strpos() 的结果.
                  2. 使用 $_SERVER['REQUEST_URI'] 而不是 $_SERVER['PHP_SELF'].
                  3. 将代码包装在函数中.

                  像这样:

                  <div id="blahblah" style="blahblah"><a <?php get_current('biography') ?>href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a><a <?php get_current('contacts') ?>href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>......

                  I have a menu like this:

                  <div id="blahblah" style="blahblah">
                  <a href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a>
                  <a href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>
                  <a href="http://domain.com/folder/gallery"><img style="blahblah" src="blahblahblahblah"></a>
                  <a href="http://domain.com/folder/dontknow"><img style="blahblah" src="blahblahblahblah"></a>
                  </div>
                  

                  I'd like to have something that automatically adds a class="current" to the page I'm currently in. Links (as you can see in the code above) are like domain.com/folder/biography or domain.com/folder/contacts, so without .php/.html, etc.

                  I tried with:

                  <div id="blahblah" style="blahblah">
                  <a <?php if (strpos($_SERVER['PHP_SELF'], 'biography')) echo 'class="current"';?> href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a>
                  <a <?php if (strpos($_SERVER['PHP_SELF'], 'contacts')) echo 'class="current"';?> href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>
                  ...
                  ...
                  </div>
                  

                  But it doesn't work... the solution with strops seems viable, probably I'm doing it wrong.. :P

                  解决方案

                  You should:

                  1. check the result of strpos() with !== false.
                  2. Use $_SERVER['REQUEST_URI'] rather than $_SERVER['PHP_SELF'].
                  3. Wrap the code inside a function.

                  Something like this:

                  <?php
                  function get_current($name) {
                    if (strpos($_SERVER['REQUEST_URI'], $name) !== false)
                      echo 'class="current"';
                  }
                  ?>
                  
                  <div id="blahblah" style="blahblah">
                    <a <?php get_current('biography') ?> href="http://domain.com/folder/biography"><img style="blahblah" src="blahblahblahblah"></a>
                    <a <?php get_current('contacts') ?> href="http://domain.com/folder/contacts"><img style="blahblah" src="blahblahblahblah"></a>
                    ...
                    ...
                  </div>
                  

                  这篇关于将特定的类/ID 应用于菜单上的当前页面 (PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Appending GET parameters to URL from lt;formgt; action(将 GET 参数附加到来自 lt;formgt; 的 URL行动)
                  Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
                  PHP - get certain word from string(PHP - 从字符串中获取某个单词)
                  How to debug a get request in php using curl(如何使用 curl 在 php 中调试 get 请求)
                  get a # from a url in php(从 php 中的 url 获取 #)
                  PHP - include() file not working when variables are put in url?(PHP - 将变量放入 url 时,include() 文件不起作用?)

                  • <small id='8167e'></small><noframes id='8167e'>

                    1. <i id='8167e'><tr id='8167e'><dt id='8167e'><q id='8167e'><span id='8167e'><b id='8167e'><form id='8167e'><ins id='8167e'></ins><ul id='8167e'></ul><sub id='8167e'></sub></form><legend id='8167e'></legend><bdo id='8167e'><pre id='8167e'><center id='8167e'></center></pre></bdo></b><th id='8167e'></th></span></q></dt></tr></i><div id='8167e'><tfoot id='8167e'></tfoot><dl id='8167e'><fieldset id='8167e'></fieldset></dl></div>
                        <bdo id='8167e'></bdo><ul id='8167e'></ul>
                        <tfoot id='8167e'></tfoot>

                          <legend id='8167e'><style id='8167e'><dir id='8167e'><q id='8167e'></q></dir></style></legend>

                            <tbody id='8167e'></tbody>