-1

购物车.php

  <div id="main-container">
  <div class="container">
  <span class="top-label">
  <span class="label-txt">Shopping Cart</span>
  </span>

  <div class="content-area">

        <div class="content drop-here">
        <div id="cart-icon">
            <img src="img/Shoppingcart_128x128.png" alt="shopping cart" class="pngfix" width="128" height="128" />
        <img src="img/ajax_load_2.gif" alt="loading.." id="ajax-loader" width="16" height="16" />
            </div>

        <form name="checkoutForm" method="post" action="order.php">

            <div id="item-list"></div>

            </form>                
            <div class="clear"></div>
            <div id="total"></div>

            <div class="clear"></div>

    <a href="" onclick="document.forms.checkoutForm.submit(); return false;" class="button">Checkout</a>

      </div>

    </div>

    <div class="bottom-container-border"></div>
   </div>



  </div>

这是 index.php

    include "cart.php";

     ....
     ....
     <div class= "cart"></div> 
     .....
      .....

      <div class="basket"><a href="#" onclick appear cart.php ><span>Shopping Basket</span></a>
      <p><span><?php echo "Amount: ".$ttl ?> </span>Item(s): <strong><?php echo $cnt ?>  </strong></p>
     </div>

我想做的是让 cart.php 出现在

  <div class= "cart"></div> 

作为一个下拉窗口,问题来了,当我加载 index.php 时,即使我在 css 文件中将 display 属性设置为 none,我也会在 index.php 的顶部拥有所有的 cart.php。

如何加载 div class = cart 中的 cart.php 而不会加载到 index.php 的顶部并且只出现在点击事件中?

提前致谢。

4

2 回答 2

0

我附上了完整的代码(使用您的 cart.php 而不做任何更改)。您也可以在小提琴上对其进行测试

<!DOCTYPE html>
<html>
    <head>
        <title>Test show()</title>
        <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
        <script>
            $(document).ready(function() {

                // Show basket on click
                $('.show_basket').on("click", function(event) {
                    $('.cart').show();
                });

                // Hide basket on click
                $('.hide_basket').on("click", function(event) {
                    $('.cart').hide();
                });

                // Toggle basket - with some extra effects
                $('.toggle_basket').on("click", function(event) {
                    $('.cart').toggle('slow');
                });
            });
        </script>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
    </head>
    <body>
        <div>
            <a href="#" class="show_basket">SHOW BASKET</a><br/>
            <a href="#" class="hide_basket">HIDE BASKET</a><br/>
            <a href="#" class="toggle_basket">TOGGLE BASKET</a>
        </div>
        <div class="cart" style="display:none;"><?php include "cart.php"; ?></div>
    </body>
</html>

将购物车的 CSS 设置为display:none;并使用 jquery(例如),您可以尝试在点击时显示它。最简单的例子在这里:http ://api.jquery.com/show/

祝你好运!

于 2013-09-09T16:31:28.623 回答
0

foo.php:

<?php
echo 'foo<br>';
?>

bar.php:

<?php
include 'foo.php';
echo 'bar<br>';
?>

显示 bar.php 输出:

foo
bar

检查您的包含订单。如果没有更清晰/更详细的解释和代码,不能说更多。

于 2013-09-09T15:25:54.883 回答