在< div>中交换值标签? [英] exchanging values in <div> tag?
本文介绍了在< div>中交换值标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的JavaScript中,有两个包含一些值的div.
In my javascript there are two divs that contains some values.
我想交换这些div中的值.
有什么解决办法吗?
I want to exchange the values in these divs.
Is there any solution ?
推荐答案
如果div中还有其他节点,并且希望保持数据和事件处理程序不变:
If you have other nodes in the divs and want to keep data and event handlers intact:
var c1 = $('#div1 > *').detach();
var c2 = $('#div2 > *').detach();
c1.appendTo('#div2');
c2.appendTo('#div1');
(或更短的;))
var c1 = $('#div1 > *').detach();
$('#div2 > *').appendTo('#div1');
c1.appendTo('#div2');
这篇关于在< div>中交换值标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文