0

在我的代码中,当div我单击. 它发生了一次,但它不会工作第二次。由于需要对移动的进行更改,我需要使用两个单独的。我想这与部分有关。你能看到它是如何工作的吗?container_twocontainerspan Add New<div>sdivparent

<!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>
4

1 回答 1

1

如果我没听错,你就错过了这个项目的克隆。

jsFiddle 演示

$('.add').click(function() {
    var $move = $('#container_two .move').clone();
    $(this).parent("div").after($move.show());
}); 
于 2013-09-08T10:31:48.623 回答