经过2小时的搜索后,我决定提问。
我有一个div:
<div id="box"></div>
我想使用jQuery在上面的div中添加一个div。
我尝试过以下代码(以下代码位于函数内部):
var e = $('<div style="display:block; float:left;width:'+width+'px; height:'+height+'px; margin-top:'+positionY+'px;margin-left:'+positionX+'px;border:1px dashed #CCCCCC;"></div>');
$('div', e).attr('id', 'myid');
$("#box").append(e);
但是访问 $("#myid")
不起作用。
有什么办法在一个 div 中添加另一个 div 并能够操作它们吗?