我正在使用Angular 中的Jquery代码,我想将一个 DIV 元素移动到另一个元素中 这是我的代码
.ts 文件
moveButton(elem) {
alert('hello' + elem);
if ( $(elem).parent().attr('id') === 'oneDiv' ) {
alert('hello' + elem);
$(elem).detach().appendTo('#anotherDiv');
} else {
$(elem).detach().appendTo('#oneDiv');
}
}
.html 文件
<div id="oneDiv">
<button id="btnDefault" class='btn123' (click)='moveButton(this)' type='button'> Button 1 </button>
<button id="btnPrimary" class='btn123' (click)='moveButton(this)' type='button' > Button 2 </button>
<button id="btnDanger" class='btn123' (click)='moveButton(this)' type='button' > Button 3 </button>
</div>
<div id="anotherDiv"> </div>
但我的代码不起作用可能是因为 detach() 、 parent() 、 attr() 不起作用。