0

jQueryを使用してクリックすると、あるdivを別のdivに置き換えようとしていますが、できません。1つのdivで非表示属性を使用する必要があるかどうかわかりません。

これがコードです

<div id="prepersonal">this is a test 1</div>
<div id="personal">this is a test 2</div>

そしてこれがcssです

#prepersonal {
   width: 330px;
   height: 330px;
   border-radius: 5px;
   background-color: #FF6801;
   color: #FFFFFF;
   font-family: Tahoma;
   padding-top:7px; 
}

#personal {
   width: 330px;
   height: 330px;
   border-radius: 5px;
   background-color: #FF6801;
   color: #FFFFFF;
   font-family: Tahoma;
   padding-top:7px;
}

誰かが答えを知ることができますか?

4

3 に答える 3

0
$(function(){
$('#prepersonal').on('click', function(){
    $(this).replaceWith($('#personal'));
});
});
于 2013-03-27T20:40:57.443 に答える
0
$(function() {
    $("#prepersonal").click(function(){
        $("#personal").html($("#prepersonal").html()); //You can use the text() method instead of html if you need only the text
        $("prepersonal").css("display", "none");
    });
);
于 2013-03-27T20:39:56.273 に答える
0

以下は、 1の内部divのコンテンツをclickedされたもののコンテンツに置き換えます。

$(function(){
    $('#prepersonal').on('click', function(){
        $('#personal').html(this.innerHTML);
    });
});

コメントの後:

$(function(){
    var a = $('#prepersonal'), b = $('#personal');

    // you can remove this call to hide by initially
    // hiding the div using display:none; in CSS
    b.hide();

    a.on('click', function(){
        toggledivs();
    });
    b.on('click', function(){
        toggledivs();
    });

    function toggledivs(){
        a.toggle();
        b.toggle();  
    };
});

http://jsfiddle.net/f6r82/

于 2013-03-27T20:33:43.660 に答える