<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1<---strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="cache-control" content="max-age=5"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script language="javascript">
function addObj() {
var input=createDiv();
document.getElementById("div1").appendChild(input);
} function createDiv(){
var td=Math.floor(Math.random()*100000);
var input = document.createElement('div');
var ind = document.createElement('input');
ind.type="text";
input.style.border="solid 1px #666";
input.id=td; var but = document.createElement('input');
but.type="button";
but.value="XIAFANG";
but.onclick=function(){
var targetE=document.getElementById(td);
var newEl=createDiv();
insertAfter(newEl, targetE);
}; var but1 = document.createElement('input');
but1.type="button";
but1.value="SHANGFANG";
but1.onclick=function(){
var ol=document.getElementById(td);
var newChild=createDiv();
document.getElementById("div1").prependChild1(newChild,ol);
}; var but3 = document.createElement('input');
but3.type="button";
but3.value="SC";
but3.onclick=function(){
var s=document.getElementById(td);
document.getElementById("div1").removeChild(s);
};
var but2 = document.createElement('input');
but2.type="button";
but2.value="XS";
but2.onclick=function(){
var s=document.getElementById(td).firstChild.value;
alert(s);};
input.appendChild(ind);
input.appendChild(but1);
input.appendChild(but);
input.appendChild(but2);
input.appendChild(but3);
return input;
}//这个是添加元素到上边
function prependChild(parent,newChild){
if(parent.firstChild){
parent.insertBefore(newChild,parent.firstChild);
} else {
parent.appendChild(newChild);
}
return parent;
}//添加到某个元素的上边
function prependChild(parent,newChild,ol){
parent.insertBefore(newChild,ol);
return parent;
}
Element.prototype.prependChild1=function(newChild,ol){ this.insertBefore(newChild,ol);
}function insertAfter(newEl, targetEl)
{
var parentEl = targetEl.parentNode; if(parentEl.lastChild == targetEl)
{
parentEl.appendChild(newEl);
}else
{
parentEl.insertBefore(newEl,targetEl.nextSibling);
}
}
</script>
</head>
<body>
<input name="dddd" value="tianjia" type="button" onclick="addObj()"/>
<div id="div1"></div>
</body>
</html>
解决方案 »
- JS如何实现图片放大效果
- 【急】这一段javascript代码有什么问题,为什么开始的时候会导致网页鼠标不停闪烁?
- jquery的jqgrid控件小问题
- EasySlider发布,顺便散分祝大家新年快乐!
- 困扰很久的firefox关于com的问题
- 如何在 FireFox 下做"设为首页"."弹出浏览器窗口"的功能?
- 请问如何控制iframe的滚动条位置
- 如何做一个右键菜单,并在一个菜单项中运行一个自编的JavaScript的函数?
- 关于iframe之间的访问
- 还是这个问题,难道纯用客户端的技术解决不了吗?在线讨论,急!!!
- 求助!为什么会is not defined?
- XML读取某一个片段的循环求助
var td=document.createElement('td');
tr.appendChild(td);
tbody.appendChild(tr)