在我的代码中,当我点击div
container_two
时,我正试图将container
从span
移到Add New
。它只发生一次,但它第二次不会工作。由于需要对移动的<div>s
进行更改,我需要使用两个单独的div
。我想这与parent
部分有关。你能看出这是如何起作用的吗?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Home</title>
<script type="text/javascript" src="http://localhost/site/scripts/jQueryCore.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.add').click(function() {
var $move = $('#container_two .move');
$(this).parent("div").after($move);
$(".move").show();
});
});
</script>
</head>
<body>
<div id="container">
<div class="h1" data-id="1">Heading One<span class="add" data-id="US01">Add New</span></div>
<div class="h2" data-id="2">Sub One <span class="add" data-id="US02">Add New</span></div>
<br>
<div class="h1" data-id="8">Head Two <span class="add" data-id="US10">Add New</span></div>
<div class="h2" data-id="9">Sub Two <span class="add" data-id="US20">Add New</span></div>
</div>
<div id="container_two">
<div class="move" style="display:none">Mock Form</div>
</div>
</body>
</html>
答案 0 :(得分:1)
如果我找对你,你就错过了这个项目的克隆。
$('.add').click(function() {
var $move = $('#container_two .move').clone();
$(this).parent("div").after($move.show());
});