单击后添加和删除div [英] add and remove div after click

查看:136
本文介绍了单击后添加和删除div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

演示

Demo

在这个演示当我点击 pop1 它删除div。当我点击 pop2 时,它会删除它并添加pop1。

In this demo when I click pop1 it removes the div. When I then click on pop2 it remove it and adds pop1.

但是当我点击 pop1 ,它(pop1)应该删除并添加 pop0 ,然后点击 pop2 当我点击 pop3 pop3 时,应删除并添加 pop1 $ c>应删除并添加 pop2

But when I click pop1, it (pop1) should remove and add pop0, then I click pop2 where it should remove and add pop1, when I click pop3, pop3 should remove and add pop2.

JS:

JS:

$(".pop").bind('click', function(){
    $('.pop').show();
   $(this).hide();     
})

在我的页面中,必须总是有3个框。

In my page, there must always be 3 boxes.

推荐答案

我不确定你在尝试做。在你的示例中甚至没有ID为pop0的元素,但是我添加了它,并默认使用 $(#pop0)隐藏它hide();

I'm not at all sure what you are trying to do. There wasn't even an element with the ID "pop0" in your example, but I added it and hid it by default with $("#pop0").hide();:

http://jsfiddle.net/ kjTBG / 16 /

HTML:

<a href='#'><div id="pop0" class="pop"></div></a>
<a href='#'><div id="pop1" class="pop"></div></a>
<a href='#'><div id="pop2" class="pop"></div></a>
<a href='#'><div id="pop3" class="pop"></div></a>

JS:

$("#pop0").hide(); // Initially hide #pop0 so it isn't visible.
$(".pop").bind('click', function(){
    $('.pop').show();
   $(this).hide();     
})

请详细说明您要做什么。改写你的问题,并使用整句话。尝试更抽象地描述它,如果这有帮助。

Please elaborate on what you are trying to do. Rephrase your question and use whole sentences please. Try to describe it more abstractly if that helps.

这篇关于单击后添加和删除div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆