-1

我正在尝试在单击时实现 jQuery div 调整大小,但是当我单击 a.dropdown-link div 时没有显示。我没有收到任何错误,但我的代码不起作用。有人可以帮我解决这个问题。这是我的 jQuery 代码:

var dd = $(".dropdown-container");

  $("a.dropdown-link").click(function(e) {
    e.preventDefault();
    e.stopPropagation();
    dd.hide("fast");
    $(this).next().find(".dropdown-container").show("fast");

  });

  $("body").click(function() {
    dd.hide();
  });

  dd.click(function(e) {
    //e.stopPropagation();
  });

还有我的 HTML:

<div id="background" class="website-not-active">

</div>

<!-- wrapper-->
<div id="wrapper">

    <!--here is the left menu-->
    <div id="left-menu" align="center">
    <!-- left logo -->
    <img src="./dashboard/images/logo.png" class="logo"/>

    <img src="./dashboard/images/user.png"/>
    <a href="#"><p>ihg <img src="dashboard/images/arr-down.png" style="padding:3px;"/></p></a>

    <a href="add_hosting.php"><p>add hosting<img src="dashboard/images/arr-down.png" style="padding:3px;"/></p></a>

    <a href="add_email.php"><p>add email<img src="dashboard/images/arr-down.png" style="padding:3px;"/></p></a>
    <a href="logout.php"><p>logout<img src="dashboard/images/arr-down.png" style="padding:3px;"/></p></a>   
    <ul id="menu" align="center">
                <a href="dashboard-ulrs-management.php"><li class="menu-first"><img src="dashboard/images/menu1.png"/></li></a>
        <li class="website-not-active"><img src="dashboard/images/menu2.png"/></li>
        <a href="dashboard-facebook-management.php"><li class="menu-third"><img src="dashboard/images/menu3.png"/></li></a>
        <a href="dashboard-email-management.php"><li class="menu-forth"><img src="dashboard/images/menu4.png"/></li></a>
        <a href="dashboard-settings-management.php"><li class="menu-fifth"><img src="dashboard/images/menu5.png"/></li></a>
    </ul>
    <p class="copyright">copyright &copy; 2013</p>
    </div>
    <!-- end left-menu-->

<!-- content div -->
    <div id="content" align="center">
<p class="welcome-message"><b><img src="./dashboard/images/website-management.png"/>
WEBSITEs UNDER MANAGEMENT</b></p>

<p class="welcome-message">
<!-- email account -->
</p><div id="website-acc">
<a class="dropdown-link" href="#"><p class="fb-head"><img src="./dashboard/images/acc_arr.png" style="margin-right:5px;"><b>WEBSITE </b></p></a>
    <div>
<div class="dropdown-container" style="display: none;">
<!-- tabela-->

<table width="50%" border="0">
  <tr>
    <td>Website URL:</td>
       <td>http://ihgcareersblog.com/</td>
  </tr>

  <tr>
    <td>Date of creation:</td>
       <td>8/7/2012</td>
  </tr>
  <tr>
    <td>Expiration date:</td>
    <td>8/6/2013</td>
  </tr>
  <tr>
    <td>Hosting Package:</td>
    <td></td>
  </tr>

</table>

</div>
    </div>
</div>
<!-- end email acc-->


<p class="welcome-message">
<!-- email account -->
</p><div id="website-acc">
<a class="dropdown-link" href="#"><p class="fb-head"><img src="./dashboard/images/acc_arr.png" style="margin-right:5px;"><b>WEBSITE </b></p></a>
    <div>
<div class="dropdown-container" style="display: none;">
<!-- tabela-->

<table width="50%" border="0">
  <tr>
    <td>Website URL:</td>
       <td>http://mysite.com/comp_hotjobsubmission</td>
  </tr>

  <tr>
    <td>Date of creation:</td>
       <td>5/31/2013</td>
  </tr>
  <tr>
    <td>Expiration date:</td>
    <td>5/31/2014</td>
  </tr>
  <tr>
    <td>Hosting Package:</td>
    <td></td>
  </tr>

</table>

</div>
    </div>
</div>
<!-- end email acc-->


<p class="welcome-message">
<!-- email account -->
</p><div id="website-acc">
<a class="dropdown-link" href="#"><p class="fb-head"><img src="./dashboard/images/acc_arr.png" style="margin-right:5px;"><b>WEBSITE </b></p></a>
    <div>
<div class="dropdown-container" style="display: none;">
<!-- tabela-->

<table width="50%" border="0">
  <tr>
    <td>Website URL:</td>
       <td></td>
  </tr>

  <tr>
    <td>Date of creation:</td>
       <td></td>
  </tr>
  <tr>
    <td>Expiration date:</td>
    <td></td>
  </tr>
  <tr>
    <td>Hosting Package:</td>
    <td>Awesome hosting</td>
  </tr>

</table>

</div>
    </div>
</div>
<!-- end email acc-->


<p class="welcome-message">
<!-- email account -->
</p><div id="website-acc">
<a class="dropdown-link" href="#"><p class="fb-head"><img src="./dashboard/images/acc_arr.png" style="margin-right:5px;"><b>WEBSITE </b></p></a>
    <div>
<div class="dropdown-container" style="display: none;">
<!-- tabela-->

<table width="50%" border="0">
  <tr>
    <td>Website URL:</td>
       <td></td>
  </tr>

  <tr>
    <td>Date of creation:</td>
       <td>08/05/2013</td>
  </tr>
  <tr>
    <td>Expiration date:</td>
    <td></td>
  </tr>
  <tr>
    <td>Hosting Package:</td>
    <td>Awesome hosting</td>
  </tr>

</table>

</div>
    </div>
</div>
<!-- end email acc-->

</div>
    <!-- end content-->

</div>
<!--end wrapper-->

这也是我的jsfiddle

4

3 回答 3

1

尝试使用以下 jQuery。它对我有用:

var dd = $(".dropdown-container");

  $("a.dropdown-link").click(function(e) {
    dd.hide("fast");
    $(this).next().find(".dropdown-container").show("fast");
      return false;

  });

  $("body").click(function() {
    dd.hide();
  });

看看这个jfiddle

于 2013-08-14T19:05:11.340 回答
1

添加这个

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

在你的脚本之前的头部之后尝试。

于 2013-08-14T19:16:40.093 回答
1

你忘了包括 jQuery 吗?添加 jQuery 后,代码在小提琴中工作。

于 2013-08-14T19:02:35.057 回答