我有一个div,其内容应该根据按钮点击改变(从另一个div的内容) 这是我的代码
<script type="text/javascript" src="../script/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../jqueryflippy/jquery.flippy.min.js"></script>
<style>
html,body{
margin:0px;
padding:0px;
height:100%;
width:100%;
overflow:hidden;
background: #757575; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzc1NzU3NSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3MDcwNzAiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, #757575 0%, #707070 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#757575), color-stop(100%,#707070)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #757575 0%,#707070 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #757575 0%,#707070 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #757575 0%,#707070 100%); /* IE10+ */
background: linear-gradient(to bottom, #757575 0%,#707070 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#757575', endColorstr='#707070',GradientType=0 ); /* IE6-8 */
}
.content{
position:relative;
top:30%;
left:20%;
height:40%;
width:60%;
border: 1px solid #ffffff;
}
.contentTitle{
height:15%;
width:100%;
color:#ffffff;
font-size:15px;
font-weight:bold;
background: #2d2d2d; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzJkMmQyZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3ZDdlN2QiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, #2d2d2d 0%, #7d7e7d 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#2d2d2d), color-stop(100%,#7d7e7d)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #2d2d2d 0%,#7d7e7d 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #2d2d2d 0%,#7d7e7d 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #2d2d2d 0%,#7d7e7d 100%); /* IE10+ */
background: linear-gradient(to bottom, #2d2d2d 0%,#7d7e7d 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#2d2d2d', endColorstr='#7d7e7d',GradientType=0 ); /* IE6-8 */
}
.contentBody{
height:85%;
width:100%;
background: #ffffff; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNlNWU1ZTUiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, #ffffff 0%, #e5e5e5 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e5e5e5)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffffff 0%,#e5e5e5 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#e5e5e5',GradientType=0 ); /* IE6-8 */
}
</style>
<script>
$(function(){
$("#content").hide();
$("#content").animate({opacity:"show"},2000);
});
function rotate(divId){
alert(divId);
$(".content").flippy({
content : $('#'+divId).clone(true, true),
direction : "TOP",
duration : "2000",
onStart : function() {
//alert("Let's flip");
},
onFinish : function() {
//alert("ok, it's flipped :)");
}
});
}
</script>
</head>
<body>
<div class="content" id="div1">
<div class="contentTitle">
<div style="padding:1% 0 0 0;">div1 Details</div>
</div>
<div class="contentBody">
<input type="button" value="Test" onclick="rotate('div2')"/>
</div>
</div>
<div class="content" id="div2" style="visibility:hidden;">
<div class="contentTitle">
<div style="padding:1% 0 0 0;">div2 Details</div>
</div>
<div class="contentBody">
<input type="button" value="Test" onclick="rotate('div3')"/>
</div>
</div>
<div class="content" id="div3" style="visibility:hidden;">
<div class="contentTitle">
<div style="padding:1% 0 0 0;">div3 Details</div>
</div>
<div class="contentBody">
<input type="button" value="Test" onclick="rotate('div1')"/>
</div>
</div>
</body>
</html>
但是在第一次翻转(其工作正常)后,按钮单击会给出相同的div内容(即div2)。 我一直坚持这一天,我们非常感谢任何帮助。
答案 0 :(得分:0)
您好,请提前查找工作代码。
错误原因:你在翻转的每个div中使用.content类,这是第一次flippy将所有div更改为类.content到div2。
检查以下工作代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Creating Popup Div | istockphp.com</title>
<link href="style.css" rel="stylesheet" type="text/css" media="all" />
<style>
html,body{
margin:0px;
padding:0px;
height:100%;
width:100%;
overflow:hidden;
background: #757575; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzc1NzU3NSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3MDcwNzAiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, #757575 0%, #707070 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#757575), color-stop(100%,#707070)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #757575 0%,#707070 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #757575 0%,#707070 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #757575 0%,#707070 100%); /* IE10+ */
background: linear-gradient(to bottom, #757575 0%,#707070 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#757575', endColorstr='#707070',GradientType=0 ); /* IE6-8 */
}
.content{
position:relative;
top:30%;
left:20%;
height:40%;
width:60%;
border: 1px solid #ffffff;
}
.contentTitle{
height:15%;
width:100%;
color:#ffffff;
font-size:15px;
font-weight:bold;
background: #2d2d2d; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzJkMmQyZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM3ZDdlN2QiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, #2d2d2d 0%, #7d7e7d 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#2d2d2d), color-stop(100%,#7d7e7d)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #2d2d2d 0%,#7d7e7d 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #2d2d2d 0%,#7d7e7d 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #2d2d2d 0%,#7d7e7d 100%); /* IE10+ */
background: linear-gradient(to bottom, #2d2d2d 0%,#7d7e7d 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#2d2d2d', endColorstr='#7d7e7d',GradientType=0 ); /* IE6-8 */
}
.contentBody{
height:85%;
width:100%;
background: #ffffff; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNlNWU1ZTUiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, #ffffff 0%, #e5e5e5 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e5e5e5)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); /* IE10+ */
background: linear-gradient(to bottom, #ffffff 0%,#e5e5e5 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#e5e5e5',GradientType=0 ); /* IE6-8 */
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="http://blog.guilhemmarty.com/flippy/jquery.flippy.min.js" type="text/javascript"></script>
<script>
$(function(){
//$("#content").hide();
$("#content").animate({opacity:"show"},2000);
});
function getHtml(divId) {
var cont = $('#'+divId).html();
alert(cont);
return cont;
}
function rotate(divId){
alert(divId);
$(".content").flippy({
content : getHtml(divId),
direction : "TOP",
duration : "500",
//verso : "test 1",
onStart : function() {
//alert("Let's flip");
},
onFinish : function() {
//alert("ok, it's flipped :)");
}
});
}
</script>
</head>
<body>
<div class="content">
<div class="contentTitle">
<div style="padding:1% 0 0 0;">div1 Details</div>
</div>
<div class="contentBody">
<input type="button" value="Test" onclick="rotate('div2')"/>
</div>
</div>
<div id="div1" style="visibility:hidden;">
<div class="contentTitle">
<div style="padding:1% 0 0 0;">div1 Details</div>
</div>
<div class="contentBody">
<input type="button" value="Test" onclick="rotate('div2')"/>
</div>
</div>
<div id="div2" style="visibility:hidden;">
<div class="contentTitle">
<div style="padding:1% 0 0 0;">div2 Details</div>
</div>
<div class="contentBody">
<input type="button" value="Test" onclick="rotate('div3')"/>
</div>
</div>
<div id="div3" style="visibility:hidden;">
<div class="contentTitle">
<div style="padding:1% 0 0 0;">div3 Details</div>
</div>
<div class="contentBody">
<input type="button" value="Test" onclick="rotate('div1')"/>
</div>
</div>
</body>
</html>