简体   繁体   English

隐藏/显示不适用于jQuery

[英]hide/show not working properly with jquery

I have a page with three rows of main information that all have a 'More Info' button attached, sort of like wefollow.com and their info button. 我有一个包含三行主要信息的页面,所有信息都附加了“更多信息”按钮,类似于wefollow.com及其信息按钮。

When the 'More Info' link is clicked a <tr> with a class of "mi" slides down above the main info. 单击“更多信息”链接时,带有“ mi”类的<tr>向下滑动到主要信息上方。

The problem that I am getting is hiding the <tr> before the 'More Info' link is clicked. 我遇到的问题是在单击“更多信息”链接之前隐藏了<tr> There is just a blank space where the <tr> is. <tr>只是空白。 The info in the <tr> is being hidden with jQuery (script below) and then displays when 'More Info' is clicked. <tr>中的信息被jQuery隐藏(下面的脚本),然后在单击“更多信息”时显示。

I tried hiding the "mi" with CSS but when the 'More Info' button is clicked, nothing happens. 我尝试使用CSS隐藏“ mi”,但是当单击“更多信息”按钮时,没有任何反应。

Any help would be awesome. 任何帮助都是极好的。 Thanks. 谢谢。

Scripts 剧本

index 指数

<table>
    <tbody>

        <tr id="info-1"> </tr>
        <tr class="mi">
            <td>
                <div id="1" class="more-information" />
            </td>
        </tr>

        <tr class="">
            <td> </td>
            <td> </td>
            <td> <a id="1" class="more-info" href="#">More info</a> </td>

    </tbody>
</table>

listing.js listing.js

$(function(){
    $(".more-information").hide();

    $(".more-info").click(function () {

    var divname= this.id;

    $("#"+divname).load("getinfo.php").slideToggle("slow").siblings().hide("slow");

    return false;
});

First problem is you're repeating IDs. 第一个问题是您要重复ID。 They need to be unique. 它们必须是唯一的。 That's no doubt throwing off your code. 毫无疑问,这会使您的代码中断。

<table>
<tbody>
  <tr id="info-1"> </tr>
  <tr class="mi">
    <td><div id="more-1" class="more-information">More information</div></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td><a id="1" class="more-info" href="#">More info</a></td>
  </tr>
</tbody>
</table>

combined with: 结合:

$(function() {
  $("a.more-info").click(function() {
    $("#more-" + this.id).load("getinfo.php").slideToggle("slow").siblings().hide("slow");
  });
});

Not sure why you need to hide siblings in the above though. 不确定为什么需要在上面隐藏同级。

Also, I wouldn't hide the "more-information" divs in jquery. 另外,我不会在jquery中隐藏“更多信息” div。 Just add CSS for that: 只需为此添加CSS:

div.more-information { display: none; }

You are hiding the more-information div but you are not hiding its parent element, the <tr> with class mi . 您正在隐藏more-information div,但没有隐藏其父元素(类mi<tr> Try putting the id attribute in the <tr> instead of the enclosed div, and hiding the whole row. 尝试将id属性放在<tr>而不是封闭的div中,然后隐藏整行。 Also, you'll have to take cletus' advice about not repeating id's and unnecessary sibling hiding. 另外,您还必须听从有关不重复id和不必要的同级隐藏的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM