【发布时间】:2011-11-18 17:56:51
【问题描述】:
我想通过单击将 div 从一个父 div 转移到另一个父 div。
请查看下面的 jsfiddle 页面以获取参考
当我单击任何灰色的 div 时,我想转移任一侧的 div .
我怎样才能做到这一点?
HTML:
<div class="section1">
<div id="1" >1</div>
<div id="2" >2</div>
<div id="3" >3</div>
<div id="4" >4</div>
<div id="5" >5</div>
<div id="6" >6</div>
<div id="7" >7</div>
<div id="8" >8</div>
</div>
<div class="section2"></div>
CSS:
.section1 div{height:25px; background-color:#333; color:#FFF; border:1px solid red; margin-bottom:2px; width:50px;}
.section2 div{height:25px; background-color:red; color:yellow; border:1px solid green; margin-bottom:2px; width:150px;}
.section1{float:left; margin-right:50px;}
.section2{float:left}
还有我的 JavaScript:
$(document).ready(function() {
function testclick() {
var iLoc = $(this).attr("id");
$('.section2').append(this);
$('#'+iLoc).unbind('click', testclick);
}
function testclick2() {
alert("s");
var iLoc = $(this).attr("id");
$('.section1').append(this);
this.unbind('click', testclick2);
}
$('.section1 div').bind('click', testclick);
$('.section2 div').bind('click', testclick2);
});
【问题讨论】:
-
能否请您也将代码包含在您的问题中。 JsFiddle 是一个很好的工具,可以补充您的问题并显示问题的实时预览,但您的问题应该独立存在。 JsFiddle 一整天都在停机,因此如果人们无法查看您的代码,您会大大降低获得答案的机会!
-
感谢 amaan 在这里添加代码,因为我在这里与互联网断开连接。
标签: javascript jquery html