onclick 隐藏所有其他兄弟 div

发布于 2024-12-17 15:20:43 字数 3600 浏览 1 评论 0原文

在我的页面中,有如下所示的列表。

<li class="select">
  <div class="type"><span class="icon_word_small bgpos"></span></div>
  <div class="docu"> <span class="fade"><a href="">Study on Clinical Research Market in AMEA</a> / 24 July 2011</span></div>
  <div class="colu"> <span class="fade"><a href="">Fairleign</a>, <a href="">Felder</a> & 2 more</span></div>
  <div class="status"><span class="fade"><span class="dark">Public</span> [2 Views 1 Downloads]</span></div>
  <div class="data_options"><a href="#" class="itemDelete">DELETE</a> </div> <!-- row hover options here-->
      <!-- popup starts here-->
    <div class="data_popup data_delete"><span class="tip"></span>Are you sure want to delete this file?
    <div class="cfix"></div>
  <ul>
    <li><a href="#" class="deletebutton"></a></li>
    <li><a href="">No,Keep this file</a></li>
  </ul>
  </div>
        <!-- popup ends here--> 
  <div class="cfix"></div>
</li>

<li>
  <div class="type"><span class="icon_word_small bgpos"></span></div>
  <div class="docu"> <span class="fade"><a href="">Study on Clinical Research Market in AMEA</a> / 24 July 2011</span></div>
  <div class="colu"> <span class="fade"><a href="">Fairleign</a>, <a href="">Felder</a> & 2 more</span></div>
  <div class="status"><span class="fade"><span class="dark">Public</span> [2 Views 1 Downloads]</span></div>

  <div class="data_options"><a href="#" class="itemShare">SHARE</a></div>  <!-- row hover options here-->
    <!-- popup starts here-->
   <div class="data_popup data_share"><span class="tip"></span><h3>Share</h3>
   <br>
  <p> <input type="checkbox" /> All in our Company</p>
     <p> <input type="checkbox" /> All in Department</p>
           <p> <input type="checkbox" id="sharetick"/> Shared with Specific People</p>
           <div id="textareamsg1"><p><textarea class="resizable" id=""></textarea></p> </div>
           <p> <input type="checkbox" id="nonsharetick"/> Do not share with specific people</p>
             <div id="textareamsg2"><p><textarea class="resizable dark" name="textarea" id="" placeholder="Type names to share document, to share with 
many seperate names with commas"></textarea></p></div>

    <div class="cfix"></div>

  <ul>
    <li><a href="#" class="okbutton"></a></li>
    <li><a href="">Cancel</a></li>
  </ul>
  </div>
      <!-- popup ends here-->
  <div class="cfix"></div>
</li>

我使用它来显示/隐藏 div.dataDelete、itemShare

$('.itemDelete').live('click', function() {
    $(this).closest("li").find('.data_delete').slideToggle('medium');
});

$('.itemShare').live('click', function() {
    $(this).closest("li").find('.data_delete').slideToggle('medium');
});

单击任何其他链接,我需要隐藏所有其他打开的 div(itemDelete 和 itemShare)。我对上面的代码也有疑问。我的客户说它有时会切换两次..我在任何浏览器中都没有遇到过这种情况。上面的代码是否有可能发生这种情况,或者他编码错误?

In my page there are lists like what is given below.

<li class="select">
  <div class="type"><span class="icon_word_small bgpos"></span></div>
  <div class="docu"> <span class="fade"><a href="">Study on Clinical Research Market in AMEA</a> / 24 July 2011</span></div>
  <div class="colu"> <span class="fade"><a href="">Fairleign</a>, <a href="">Felder</a> & 2 more</span></div>
  <div class="status"><span class="fade"><span class="dark">Public</span> [2 Views 1 Downloads]</span></div>
  <div class="data_options"><a href="#" class="itemDelete">DELETE</a> </div> <!-- row hover options here-->
      <!-- popup starts here-->
    <div class="data_popup data_delete"><span class="tip"></span>Are you sure want to delete this file?
    <div class="cfix"></div>
  <ul>
    <li><a href="#" class="deletebutton"></a></li>
    <li><a href="">No,Keep this file</a></li>
  </ul>
  </div>
        <!-- popup ends here--> 
  <div class="cfix"></div>
</li>

<li>
  <div class="type"><span class="icon_word_small bgpos"></span></div>
  <div class="docu"> <span class="fade"><a href="">Study on Clinical Research Market in AMEA</a> / 24 July 2011</span></div>
  <div class="colu"> <span class="fade"><a href="">Fairleign</a>, <a href="">Felder</a> & 2 more</span></div>
  <div class="status"><span class="fade"><span class="dark">Public</span> [2 Views 1 Downloads]</span></div>

  <div class="data_options"><a href="#" class="itemShare">SHARE</a></div>  <!-- row hover options here-->
    <!-- popup starts here-->
   <div class="data_popup data_share"><span class="tip"></span><h3>Share</h3>
   <br>
  <p> <input type="checkbox" /> All in our Company</p>
     <p> <input type="checkbox" /> All in Department</p>
           <p> <input type="checkbox" id="sharetick"/> Shared with Specific People</p>
           <div id="textareamsg1"><p><textarea class="resizable" id=""></textarea></p> </div>
           <p> <input type="checkbox" id="nonsharetick"/> Do not share with specific people</p>
             <div id="textareamsg2"><p><textarea class="resizable dark" name="textarea" id="" placeholder="Type names to share document, to share with 
many seperate names with commas"></textarea></p></div>

    <div class="cfix"></div>

  <ul>
    <li><a href="#" class="okbutton"></a></li>
    <li><a href="">Cancel</a></li>
  </ul>
  </div>
      <!-- popup ends here-->
  <div class="cfix"></div>
</li>

I'm using this to show/hide div.dataDelete, itemShare

$('.itemDelete').live('click', function() {
    $(this).closest("li").find('.data_delete').slideToggle('medium');
});

$('.itemShare').live('click', function() {
    $(this).closest("li").find('.data_delete').slideToggle('medium');
});

on clicking any other links, i need to hide all other open divs( both itemDelete and itemShare). Also I have a doubt in the above code. My client says it is toggling twice sometimes.. I did not experience that in any browsers. Is there any chance that this could occur with the code above or is he coded that wrongly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妞丶爷亲个 2024-12-24 15:20:43

执行以下操作:

$(".data_options a").live("click", function(e){
    e.preventDefault();
    $(".data_popup").slideUp();
    $(this).closest(".select").find(".data_popup").stop(true, false).slideDown();
});

您单击的链接都在:.data_options 内。所以我们可以用它作为参考,而不是我们找到所有包含您想要slideUp的所有DIV的.data_popup,除了当前的DIV之外,您不想滑动那个下来了。

如果它切换两次,它可能会被绑定两次?或者双击而不是单击。使用上面的代码,当前项目将始终打开而不是切换。

Do something like:

$(".data_options a").live("click", function(e){
    e.preventDefault();
    $(".data_popup").slideUp();
    $(this).closest(".select").find(".data_popup").stop(true, false).slideDown();
});

The link you are click are both inside: .data_options. So we can use that as a reference, not we find all .data_popup which contains all DIV's you want to slideUp, except for the current one, you wan't to slide that one down.

If it toggles twice, it might be bound twice? Or the do a double click instead of a single click. With above code, current item will always go open instead of toggle.

一页 2024-12-24 15:20:43

请尝试这个:

var q = 0;
$('.itemDelete, .itemShare').live('click',
function() {
    if (q == 1) {
        q = 0;
        $(this).parent().next('.data_delete, .data_share').slideToggle();
    } else {
        q = 1;
        $('.data_delete, .data_share').not($(this).parent().next('.data_delete, .data_share')).slideToggle();
    }
});

please try this:

var q = 0;
$('.itemDelete, .itemShare').live('click',
function() {
    if (q == 1) {
        q = 0;
        $(this).parent().next('.data_delete, .data_share').slideToggle();
    } else {
        q = 1;
        $('.data_delete, .data_share').not($(this).parent().next('.data_delete, .data_share')).slideToggle();
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文