doumu1212 2016-12-23 10:03
浏览 49
已采纳

下拉列表链接到同一页面中具有直接href的另一个页面

Having problem linking to page content with the dire href I wanted.

current dropdown list

Right now if I click on the dropdown list, it will go to armchair. e.g. click on sofa still go armchair.

How do I go to other category?

The information are stored in the same page, for all the category. I need to display the right content when users click on the different category.

This is the array that I have in productData.php for the list

$collectionArr = [
["catCode"=>"ac", "catName"=>"Armchair"],
["catCode"=>"sf", "catName"=>"Sofa"],
["catCode"=>"st", "catName"=>"Side Table"],
["catCode"=>"ct", "catName"=>"Coffee Table"],
["catCode"=>"dt", "catName"=>"Table"],
["catCode"=>"cs", "catName"=>"Chair / Stool"],
["catCode"=>"sb", "catName"=>"Side Board"],
];

my collectiondropdown.php

  foreach ($collectionArr as $name => $liDetail) {
  echo "<a href='collectionPage.php#{$liDetail["catCode"]}' {$liDetail["catName"]}</a><hr />";

}

My HTML for the menu

<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Collection <b class="caret"></b></a>
    <ul class="dropdown-menu">
      <?php include 'productData.php'; ?>
        <?php
           include 'collectiondropdown.php'
         ?>
    </ul>
  </li>   

HTML that stores all the content

<div id="ac">
<ul>
<li><a name="ac" href="collectionPage.php?cat=ac&page=1">1</a></li>
<li><a name="ac" href="collectionPage.php?cat=ac&page=2">2</a></li>
<li><a name="ac" href="collectionPage.php?cat=ac&page=3">3</a></li>
<li><a name="ac" href="collectionPage.php?cat=ac&page=4">4</a></li>
<li><a name="ac" href="collectionPage.php?cat=ac&page=5">5</a></li>
<li><a name="ac" href="collectionPage.php?cat=ac&page=6">6</a></li>
<li><a name="ac" href="collectionPage.php?cat=ac&page=7">7</a></li>
</ul>
 <!-----Page 1-------------------->
 <div id="acPage1" class="page" style="">
   <p>List of content after clicking 1</p>
 </div>
<!-----Page 2-------------------->
 <div id="acPage2" class="page" style="display:none">
   <p>List of content after clicking 2</p>
 </div>
</div><!----end of ac--->

<div id="sf">
<ul>
<li><a name="sf" href="collectionPage.php?cat=sf&page=1">1</a></li>
<li><a name="sf" href="collectionPage.php?cat=sf&page=2">2</a></li>
<li><a name="sf" href="collectionPage.php?cat=sf&page=3">3</a></li>
</ul>
<!-------Same as ac-------->
</div>
<div id="st">
xxxxxxxxxxx
</div>
<div id="ct">
xxxxxxxxxxx
</div>
<div id="dt">
xxxxxxxxxxx
</div>
<div id="cs">
xxxxxxxxxxx
</div>
<div id="sb">
xxxxxxxxxxx
</div>
  • 写回答

1条回答 默认 最新

  • doulao2916 2016-12-23 10:49
    关注

    If I understood your problem correctly, then named anchors can be a solution. For that following changes need to be implemented -

    In HTML page insert the named anchors. I suggest enclosing the first word in the div in a named anchor as below -

    <div id="ac">
        <a name="ac">x</a>xxxxxxxxxx
    </div>
    <div id="sf">
        <a name="sf">x</a>xxxxxxxxxx
    </div>
    <div id="st">
        <a name="st">x</a>xxxxxxxxxx
    </div>
    ....
    ....
    <div id="sb">
        <a name="sb">x</a>xxxxxxxxxx
    </div>
    

    And for dynamic list, update code as follows to have the links point to the named anchors -

    foreach ($collectionArr as $name => $liDetail) {
        echo "<a href='collectionPage.php#{$liDetail["catCode"]}'>{$liDetail["catName"]}</a><hr />";
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像