如何更换div中的信息
问题描述:
我试图用jQuery替换一个div,但我不能这样做,我不知道是否需要使用hide属性一格。如何更换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;
}
有人可以知道答案吗?
答
以下内容替换内一个div
内容与一个内容,这是click
编辑:
$(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();
};
});
+0
个人div必须隐藏,当你点击prepersonal,隐藏prepersonal和显示个人 – 2013-03-27 20:42:30
答
$(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");
});
);
答
$(function(){
$('#prepersonal').on('click', function(){
$(this).replaceWith($('#personal'));
});
});
什么是您的JavaScript? – 2013-03-27 20:35:04
这是不清楚的,删除如删除并插入另一个div。或隐藏你的一个divs? – 2013-03-27 20:36:00
你需要更换什么'div'? – adamdehaven 2013-03-27 20:36:03