如何创造并追加到文档主体的元素? (角) [英] how can create and append an element to document body? (angular)
本文介绍了如何创造并追加到文档主体的元素? (角)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在指令我想创建一个div并将其追加到文档中。我究竟做错了什么?
VAR发= angular.element('< DIV>< / DIV>'); mover.css({
位置:绝对,
顶部:0像素,
底部:0像素,
左:'33px',
宽度:50像素,
背景:'蓝',
zIndex的:'2'
}); $ document.append(发);
解决方案
好了,你还有你的元素添加另一个元素。尝试是这样的:
VAR身体= $ document.find(身体),EQ(0);
body.append(发)
In a directive i want to create a div and append it to the document. what am i doing wrong?
var mover = angular.element('<div></div>');
mover.css({
position: 'absolute',
top: '0px',
bottom: '0px',
left: '33px',
width: '50px',
background: 'blue',
zIndex: '2'
});
$document.append( mover );
解决方案
Well, you still have to append your element on on another element. Try something like this:
var body = $document.find('body').eq(0);
body.append(mover)
这篇关于如何创造并追加到文档主体的元素? (角)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文