如何在使用jquery提交时将项目从一个div移动到另一个选中的复选框
大家好,我正在处理jquery,这里我有一个类似这样的html代码如何在使用jquery提交时将项目从一个div移动到另一个选中的复选框,jquery,Jquery,大家好,我正在处理jquery,这里我有一个类似这样的html代码 <div> <span class="span1"> <label class="checkbox" /> <input type="checkbox" class="regular-checkbox" id="Header" /> <label for="Header"></label>
<div>
<span class="span1">
<label class="checkbox" />
<input type="checkbox" class="regular-checkbox" id="Header" />
<label for="Header"></label>
</label>
</span>
<span class="span1">Images</span>
<span class="span1">SKU</span>
<span class="span2">Name</span>
<span class="span1">Price</span>
</div>
<div id="separate"></div>
<input type="button" id="button" />
我试过这样做,但没用
<script type="text/javascript">
$(document).ready(function(){
$(#button).click(function(){
$(function () {
$("input:checkbox").toggle(function () {
$("#Header").appendTo("#separate");
},function () {
$("#separate").appendTo($(this));
});
});
});
</script>
我有这个DIV,我有一个复选框,从这里我有一个图像,价格和名称的手机。这是我的代码,我有一个“href”图标
当我选中复选框,并且提交了图像,并且价格和名称应该移动到另一个DIV时,我如何做到这一点,以及当我取消选中复选框时?
它应该切换。你能帮我解决这个问题吗,提前谢谢。我会这样做的 JavaScript:
$(function () {
// Check if user clicks on the checkbox
$("#Header").click(function() {
if($('#Header').is(':checked')){
// If the checkbox becomes checked,
// move the contents to our new div (div2)
$("#div1").contents().appendTo("#div2");
} else {
// Otherwise we can assume it is being unchecked,
// so move everything back to it's original div (div1)
$("#div2").contents().appendTo("#div1");
}
});
});
HTML标记:
我对您的标记做了很多清理,您有开放标签标签,您可能应该将要移动的元素放在它们自己的包装器div中,以使事情变得简单
<span class="span1">
<label for="Header"></label>
<input type="checkbox" class="regular-checkbox" id="Header" />
</span>
<div id="div1">
<span class="span1">Images</span>
<span class="span1">SKU</span>
<span class="span2">Name</span>
<span class="span1">Price</span>
</div>
<div id="div2"></div>
您需要什么并不十分清楚,但可能会导致解决方案:
<input type="checkbox" class="regular-checkbox" id="Header" />
<br/>
Pos:1
<div id="oryginal">
<span class="span1">Images</span>
<span class="span1">SKU</span>
<span class="span2">Name</span>
<span class="span1">Price</span>
</div>
<br/>
Pos:2
<div id="separate"></div>
$("input:checkbox").toggle(
function () {
$("#oryginal span").appendTo("#separate");
},function () {
$("#separate span").appendTo("#oryginal");
});
Shakil,即使在我编辑之后,我也很难理解你到底想在这里完成什么。例如:您提到了一些HTML标记中不存在的元素,如$separate。请再读一遍你的问题,让它明白。帮助我们帮助您:k感谢编辑我现在将Sory我现在将更新是的我已尝试将另一个div的id附加到该div感谢我的回复jeemusu,但我的任务已更新它应在提交功能k上工作,我将有一个复选框的编号,它应该只添加选定的。您可以帮助我plzjeemu感谢我的回复吗看,我会解释你我有div在这我有一些内容,像图像和名称和价格现在我需要这些图像来编辑div only选中一个我会有多个复选框当我选中复选框,当我点击按钮时,图像应该移动到另一个div。如果可以的话,请帮助我这样做。非常感谢,seemu这是工作,我得到了,非常感谢