如何将我创建的DIV包含在另一个DIV中?
How can I contain the DIV I create inside another DIV?
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<title>Javascript Create Div Element Dynamically</title>
<style type="text/css">
.ex {
width:200px;
position: relative;
background-color :#CCC;
height:150px;
padding:10px;
margin:5px;
left-margin:0px;
float :left;
}
.newdiv {
width:800px;
height:800px;
border:1px solid #000;
}
#myimage {
height: 80;
width: 80;
top:100;
margin:5px;
}
.border {
border:1px solid #000;
}
</style>
<script>
cc = 1;
function changeimage() {
if (cc == 0) {
cc = 1;
document.getElementById('myimage').src = "http://forums.hardwarezone.com.sg/images/white_contact.png";
} else if (cc == 1) {
cc = 2;
document.getElementById('myimage').src = "http://forums.hardwarezone.com.sg/images/yellow_contact.png";
} else if (cc == 2) {
cc = 3;
document.getElementById('myimage').src = "http://forums.hardwarezone.com.sg/images/red_contact.png";
} else {
cc = 0;
document.getElementById('myimage').src = "http://forums.hardwarezone.com.sg/images/green_contact.png";
}
}
</script>
<script type="text/javascript" language="javascript">
var i = 0;
function createDiv() {
if (i < 6) {
var divTag = document.createElement("div");
divTag.id = "div1";
divTag.setAttribute("align", "left");
divTag.style.margin = "0px auto";
divTag.className = "ex";
divTag.innerHTML = "<img id='myimage' onclick='changeimage()' border='0' src='images/white_contact.png' width='100' height='180' />";
document.body.appendChild(divTag);
$("div.newdiv").html("<div class='ex'><img onclick='changeimage()' src='images/white_contact.png'/></div>");
}
i++;
$(".ex").draggable({
containment: 'parent',
cursor: 'pointer',
opacity: 0.6
});
$(".ex").droppable({
hoverClass: 'border'
});
}
</script>
</head>
<body>
<p align="left"> <b>Click this button to create div element dynamically:</b>
<input id="btn1" type="button" value="create div" onClick="createDiv();" />
<div class="newdiv"></div>
</p>
</body>
</html>
这是我到目前为止所做的。我如何在我的#newDIV
类中创建所有6个div
元素?我只能在
父容器不工作,我该怎么办?请帮助。
我需要6div是draggable
在newDiv
也....
是啊,真的很简单…你可以嵌套div
<div class=newdiv><div class=ex></div></div>
基本上就是嵌套——第一个嵌套第二个div,第二个嵌套第一个。
相关文章:
- 如果Div包含精确文本,则添加类
- 获取包含单击链接的DIV的文本
- 如何获取并返回包含Id的Div
- 如何将来自外部 PHP 页面的内容包含在带有 onlick 事件的 DIV 中
- JQuery if 语句基于在文本中包含特定字符串将数据追加到相应的 DIV
- 覆盖在“背景大小:包含”上的响应式 DIV - 解决警报触发的问题
- 如果 DIV 包含选中的复选框,则将显示设置为阻止
- 背景轮播,用于在幻灯片图像中包含 DIV
- 修改脚本以在上午/下午前后包含 DIV
- 重置表单,但包含在 DIV 中的输入除外
- 通过混合输入值,在 DIV 内制作一个包含输入的矩阵
- 重新加载仅包含脚本的 DIV,然后执行脚本
- 重新加载包含DB值的DIV
- 打印包含动态图像的Div
- 如何显示与其他人一起包含的选择的隐藏DIV
- 包含注册表单的Div在我单击提交后消失
- 如何将我创建的DIV包含在另一个DIV中?
- 隐藏DIV,如果它包含特定的文本
- 如果子DIV包含特定的CLASS和STYLE属性,则指定DIV ID
- Javascript-快速重新加载DIV(包含php代码)