<!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">
<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="red";
box.innerHTML="fsfsafasf"+num;
document.getElementById("div_pannel").appendChild(box);
// 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(){
var cont =delId;
cont.parentNode.removeChild(cont);
}
//得到要删除的DIV的ID
function divId(aa){
delId=document.getElementById(aa);
}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="删除" onclick="delBotton()" />
<div id="div_pannel">
</div>
</form>
<div onclick="abb()">点击</div>
</body>
</html> 想让点击删除任意一个,上面的序号从新排序
<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="red";
box.innerHTML="fsfsafasf"+num;
document.getElementById("div_pannel").appendChild(box);
// 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(){
var cont =delId;
cont.parentNode.removeChild(cont);
}
//得到要删除的DIV的ID
function divId(aa){
delId=document.getElementById(aa);
}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="删除" onclick="delBotton()" />
<div id="div_pannel">
</div>
</form>
<div onclick="abb()">点击</div>
</body>
</html> 想让点击删除任意一个,上面的序号从新排序
解决方案 »
- 在一个网站上调用uchome的导航信息和用户信息!
- 添加dtd文档了,javascript失效。
- [求助]我这小程序哪错了?
- 在IE7.0或者遨游浏览器下,怎样使刷新按钮失效(别跟我说屏蔽按键F5,谢谢)
- 文本编辑器
- 如何使用javascript来获得同一个Form下的多个按钮的名称(或name)???
- 数据转换问题
- 请问如何在打开一个新窗口后立即关闭原来的旧窗口?
- 高分求得到当前文件夹下的所有文件名或文件夹名称的写法?
- 请教各位一个很简单的有关JavaScript的问题,马上给分的!!!
- jQuery插件中调用自身函数险入死循环...求高人指点
- js 鼠标移动到某位置,某位置隐藏的图片就显示出来,当鼠标移走,图片又隐藏了。鼠标移动到其他地方,其他地方的图片又出现
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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="red";
box.innerHTML="fsfsafasf"+num;
document.getElementById("div_pannel").appendChild(box);
// 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(){
var divs = document.getElementById('div_pannel').getElementsByTagName('div');
document.getElementById('div_pannel').removeChild(divs[divs.length - 1]);
num--;
}
//得到要删除的DIV的ID
function divId(aa){
delId=document.getElementById(aa);
}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="删除" onclick="delBotton()" />
<div id="div_pannel">
</div>
</form>
<div onclick="abb()">点击</div>
</body>
</html>帮你改了下
就假设当前你要删的div为第N个
从N开始向下 改ID属性不就行了
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body><script type="text/javascript"> //<![CDATA[ var container = null; window.onload = pageInit; function pageInit()
{
container = document.getElementById("container"); createDivs();
} function createDivs()
{
var fragment = document.createDocumentFragment();
var div = null;
for (var i = 0; i < 10; i++)
{
div = document.createElement("div");
div.appendChild(document.createTextNode(i));
fragment.appendChild(div);
}
container.appendChild(fragment);
} function deleteLastDiv(deleteIndex)
{
container.removeChild(container.childNodes[deleteIndex]);
//重排序
var len = container.childNodes.length;
for (var i = 0; i < len; i++)
container.childNodes[i].innerHTML = i;
} //]]></script><div id="container"></div><input type="button" onclick="deleteLastDiv(2)" value="delete(2)" /></body>
</html>