为什么我不能追加一个元素,将其删除,然后附加相同元素的第二次? [英] Why can't I append an element, remove it, then append the same element a second time?
问题描述
在下面提供的code,你会看到由各种瓷砖的地图。点击瓷砖将选择了。
In the code provided below, you will see a map made of various tiles. Clicking on a tile will "select" it.
我想会发生什么:
- 单击一个区块
- preSS的放置按钮
- 一个井架出现在了瓷砖
- preSS的删除按钮
- 的井架消失
- 单击另一个tile
- preSS的放置按钮
- 新的井架出现在了瓷砖
该项目工程直到步骤7-8。出于某种原因,井架不会再次出现。
The program works up until steps 7-8. For some reason, the oil derrick isn't appearing again.
我有地点
和删除
设置,使只有一个井架可能是按钮在地图上以时间:要删除一个井架,我不希望与它的石油井架瓦去除(因此前被选中,你可以有不同的瓷砖选择并单击删除仍将删除井架不管它是什么瓦上)。
I have the Place
and Remove
buttons set up so that only one oil derrick may be on the map at a time. To remove an oil derrick, I do not expect the tile with the oil derrick on it to be selected before removal (hence, you can have a different tile selected and clicking Remove will still remove the oil derrick no matter what tile it is on).
我觉得问题是,井架是没有得到正确追加第二次。这可能是因为它被移除的方式。
What I think is the problem is that the oil derrick isn't getting appended correctly the second time. This may be because of the way it's being removed.
http://jsfiddle.net/briz/jdhPW/17/
不是在一个侧面,
我认识到,有一个潜在的错误,如果Place按钮得到选择瓷砖之前pressed。
On a side not, I realize that there is a potential bug if the Place button gets pressed before a tile is selected.
推荐答案
有很多方法可以解决这个问题。我想最简单的将是$('。oilDerrick')。隐藏(),而不是删除()。另一种方法是追加的克隆和更改类名,这需要改变虽然更位code。
There are many ways to fix this. I think the simplest would be to $('.oilDerrick').hide() rather than remove(). An alternative would be to append clones and change class names, that requires changing a bit more code though.
更新: http://jsfiddle.net/jdhPW/19/一>
这篇关于为什么我不能追加一个元素,将其删除,然后附加相同元素的第二次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!