<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
//添加层
var num=1;
function CreateDiv()
{
var box = document.createElement("div");
box.id= "div_"+num;
box.setAttribute("onclick","divId('div_"+num+"')");
box.style.width="100px";
box.style.height="100px"
box.style.backgroundColor="#ffccff";
box.innerHTML="fsfsafasf"+num;
document.getElementById("div_pannel").appendChild(box);
box.onclick = divId;
// document.getElementById('text'+num).focus();
num+=1; }
/*
function RemoveDiv(obj)
{
var ob = document.getElementById(obj);
ob.parentNode.removeChild(ob);
}
/*
function abb(){
document.getElementById('text'+num).focus();
}*///删除
function delBotton(a){
document.getElementById('div_pannel').removeChild(a)
}
//得到要删除的DIV的ID
function divId(){
//this.style.border = '1px solid blue';
this.style.backgroundColor="yellow";
var that = this;
document.getElementById('shanchu').onclick = function(){
document.getElementById('div_pannel').removeChild(that);
var divs = document.getElementById('div_pannel').getElementsByTagName('div');
for(var i = 0; i < divs.length; i++){
divs[i].innerHTML="fsfsafasf"+(i+1);
}
num = divs.length+1;
};
}
/*
function blurInput(inputId)
{
var input=document.getElementById(inputId);
input.style.border="hidden";
input.style.background="#eeeeee";
}
*/
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="新增" onclick="CreateDiv()" /><input type="button" value="删除" id="shanchu" />
<div id="div_pannel">
</div>
</form></body>
</html>点击按钮让增加的每个div层,鼠标都可以放上去移动,而且还可以拖拽div层的大小
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
//添加层
var num=1;
function CreateDiv()
{
var box = document.createElement("div");
box.id= "div_"+num;
box.setAttribute("onclick","divId('div_"+num+"')");
box.style.width="100px";
box.style.height="100px"
box.style.backgroundColor="#ffccff";
box.innerHTML="fsfsafasf"+num;
document.getElementById("div_pannel").appendChild(box);
box.onclick = divId;
// document.getElementById('text'+num).focus();
num+=1; }
/*
function RemoveDiv(obj)
{
var ob = document.getElementById(obj);
ob.parentNode.removeChild(ob);
}
/*
function abb(){
document.getElementById('text'+num).focus();
}*///删除
function delBotton(a){
document.getElementById('div_pannel').removeChild(a)
}
//得到要删除的DIV的ID
function divId(){
//this.style.border = '1px solid blue';
this.style.backgroundColor="yellow";
var that = this;
document.getElementById('shanchu').onclick = function(){
document.getElementById('div_pannel').removeChild(that);
var divs = document.getElementById('div_pannel').getElementsByTagName('div');
for(var i = 0; i < divs.length; i++){
divs[i].innerHTML="fsfsafasf"+(i+1);
}
num = divs.length+1;
};
}
/*
function blurInput(inputId)
{
var input=document.getElementById(inputId);
input.style.border="hidden";
input.style.background="#eeeeee";
}
*/
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" value="新增" onclick="CreateDiv()" /><input type="button" value="删除" id="shanchu" />
<div id="div_pannel">
</div>
</form></body>
</html>点击按钮让增加的每个div层,鼠标都可以放上去移动,而且还可以拖拽div层的大小
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货