English 中文(简体)
显示目前被点击的div 躲藏,此前被点击的div
原标题:show current clicked div hide previous clicked div
  • 时间:2010-03-24 17:10:29
  •  标签:
  • jquery

The code below is working, but with a problem I do not understand. When I click on first navigation link it is showing the div, this is what I want, but when I click on another nav link it does show the next div as expected but I need for the previous div(s) to hide. any help is appreciated.

比如,如果这不是被点击的暗中线。 我想。

$(document).ready(function(){

  $( #navigation a ).click(function (selected) {

    var getName = $(this).attr("id");
    var projectImages = $(this).attr("name");

    //console.log(getName);
    //console.log(projectImages);

    $(function() {     
      $("#" + projectImages ).show("normal");
    });
  });
});
最佳回答

你可以尝试为你所展示的四分之一添加一栏,然后在你显示新的四分五裂时,将有关内容藏匿起来。 与此类似:

$(document).ready(function(){ 

  $( #navigation a ).click(function (selected) { 

    var getName = $(this).attr("id"); 
    var projectImages = $(this).attr("name");

    $(function() {      
      $(".current").hide().removeClass("current");
      $("#" + projectImages ).show("normal").addClass("current");
    }); 
  }); 
}); 
问题回答

我一般会通过将一个类别分配给一个<代码><div>,以总结所有需要隐藏的图像来实现这一功能。 然后,每点击,就隐藏适当的四肢,并显示你需要的东西:

$(document).ready(function(){
  $( #navigation a ).click(function (selected) {

    var getName = $(this).attr("id");
    var projectImages = $(this).attr("name");

    $( div.special_images ).hide();
    $("#" + projectImages ).show("normal");
  });
});

另外,你也没有必要总结一下你的项目。 图像显示代码:

$(function() { ... });

这是你上述法典的一个捷径:

$(document).ready(function() {...});

这已经概括了你的法典。

如果你再次藏匿/how的分子在任何内容中都是兄弟姐妹,这将发挥作用:

$(function(){
  $( #navigation a ).click(function () {
    $("#" + $(this).attr("name")).siblings().hide().end().show("normal");
  });
});

at:

<ul id= navigation >
    <li><a href= #  id= nav1  name= nav1menu >Link 1</a><ul id= nav1menu >...</ul></li>
    <li><a href= #  id= nav2  name= nav2menu >Link 2</a><ul id= nav2menu >...</ul></li>
    <li><a href= #  id= nav3  name= nav3menu >Link 3</a><ul id= nav3menu >...</ul></li>
</ul>

阁下问“最后”点击,但问题结束似乎意味着所有其他人都应关闭。 在这种情况下:

$(document).ready(function(){

  $( #navigation a ).click(function (selected) {

    var getName = $(this).attr("id");
    var projectImages = $(this).attr("name");

    //console.log(getName);
    //console.log(projectImages);

    $(function() {
      $( #navigation ul ).hide();
      $("#" + projectImages ).show("normal");
    });
  });
});

通知说,在我们点击之前,我们藏匿所有铀弹。

Hope that helps, Joe

我猜测这些潜水器是航行的一部分。 追踪最后一件事打开了,然后隐藏在后面。

var = previousProjectImage = "";

$(document).ready(function(){

  $( #navigation a ).click(function (selected) {

    var getName = $(this).attr("id");
    var projectImages = $(this).attr("name");

    //console.log(getName);
    //console.log(projectImages);

    $(function() {
      if(previousProjectImage != "") {
        $("#" + previousProjectImage).hide();
      }    
      $("#" + projectImages ).show("normal");
      previousProjectImage = projectImages;
    });
  });
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签