用 insertBefore 增加节点,怎么会多出很多 <div></div>?
解决方案 »
- 菜鸟看到一段代码,学到两个知识点,发出来和大家玩一下
- Ext.grid.ColumnModel 显示不正常 求救!
- js加载xml 火狐3.6.3
- 在submit时,我想提交一个值。怎么办
- 请教JavaScript树型目录不兼容火狐浏览器的问题
- ActiveXObject 的responseText的值 各位老大帮帮忙
- 急!!!如果在没有body的页面载入时运行javascript函数???
- 提交数据而不跳转,求JS
- 如何获得一个控件离页面顶点top = 0得距离?也就是说,他相对于页面的top是多少?
- 如何替换表格的背景图片
- 请教高手表单内容为数字范围的实时校验如何实现
- 高人们,帮忙看看为什么提示说函数未定义呢?
添加后的效果<DIV onclick="gg()">
<IMG src="Images/m.gif" name=p298>
<SPAN onselectstart=event.returnvalue=false; onmouseover="this.style.color='#003399';this.style.cursor='default';this.style.cursor='hand';this.style.textDecoration='underline'" style="LEFT: 2px; CURSOR: hand; COLOR: #000000; POSITION: relative; TEXT-DECORATION: none" onmouseout="this.style.color='#000000';this.style.textDecoration='none'">
sss
</SPAN>
</DIV>
</DIV>
<DIV>
<DIV id=d298 style="DISPLAY: block; LEFT: 15px; POSITION: relative"><DIV>
<DIV><DIV onclick="gg()">
<IMG src="Images/m.gif" name=p300>
<SPAN onselectstart=event.returnvalue=false; onmouseover="this.style.color='#003399';this.style.cursor='default';this.style.cursor='hand';this.style.textDecoration='underline'" style="LEFT: 2px; CURSOR: hand; COLOR: #000000; POSITION: relative; TEXT-DECORATION: none" onmouseout="this.style.color='#000000';this.style.textDecoration='none'">
ssss
</SPAN>
</DIV>
</DIV>
<DIV>
<DIV id=d300 style="DISPLAY: block; LEFT: 15px; POSITION: relative">
<DIV onselectstart=event.returnvalue=false; id=d301 onmouseover="this.style.color='#003399';this.style.cursor='default';this.style.cursor='hand';this.style.textDecoration='underline'" style="CURSOR: hand; COLOR: #000000; TEXT-DECORATION: none" onclick=rc() onmouseout="this.style.color='#000000';this.style.textDecoration='none'">
sss
</DIV>
</DIV>
</DIV>
</DIV>
<DIV onselectstart=event.returnvalue=false; id=d299 onmouseover="this.style.color='#003399';this.style.cursor='default';this.style.cursor='hand';this.style.textDecoration='underline'" style="CURSOR: hand; COLOR: #000000; TEXT-DECORATION: none" onclick=rc() onmouseout="this.style.color='#000000';this.style.textDecoration='none'">
ss
</DIV>
</DIV>
</DIV>
</DIV>
</DIV>
这个是代码
function branchNewNode(x,y,level,scale,childId,childTitle,anchorId)
{
if (typeof(anchorId) != "undefined")
{
var x = x;
var y = y;
var level = level;
var scale = scale;
var childId = childId;
var childTitle = childTitle;
var anchorId = anchorId;
var childNode = document.createElement("div");
var anchor = document.getElementById(anchorId) if (anchor.getElementsByTagName("div").length > 0 ) //在根节点添加节点
{
anchor.insertBefore(childNode,removeTextNode(anchor.childNodes[0])); // getElementsByTagName("div")
var dd = "<div id=\"" + childId + "\"onselectstart=\"event.returnvalue=false;\"onmouseover=\"this.style.color='#003399';this.style.cursor='default';this.style.cursor='hand';this.style.textDecoration='underline'\"onmouseout=\"this.style.color='#000000';this.style.textDecoration='none'\"onclick=\"rc(" + x + "," + y + "," + level + "," + scale + "," + childId + ")\">" + childTitle + "</div>"
childNode.innerHTML = dd;
if (anchor.style.display == "none")
{
anchor.style.display = "block";
document.getElementById(anchorId.replace("d","p")).src = "Images/m.gif";
}
}
else //叶节点添加节点
{
var anchorUp = anchor.parentNode.childNodes //getElementsByTagName("div") var z = anchorUp.length //
for(var i = 0; i < z; i++)
{
if (anchorUp[i].id == anchorId)
{
break;
}
}
var imageId = anchorId.replace("d","p");
anchorTitle = anchor.innerText;
var functionHead = anchor.onclick.toString();
functionHead = "gg" + functionHead.substring(25,functionHead.length - 3) + "," + imageId + ",'')";
var aa = "<div onclick=\"" + functionHead + "\">" +
"<img name=\"" + imageId + "\"src=\"Images/m.gif\">" +
"<span onselectstart=\"event.returnvalue=false;\"onmouseover=\"this.style.color='#003399';this.style.cursor='default';this.style.cursor='hand';this.style.textDecoration='underline'\"onmouseout=\"this.style.color='#000000';this.style.textDecoration='none'\"style=\"left:2;position:relative\">" +
anchorTitle +
"</span>" +
"</div>";
var bb = "<div id=\"" + anchorId + "\"style=\"display:block;left:15px;position:relative\">" +
"<div id=\"" + childId + "\" onselectstart=\"event.returnvalue=false;\"onmouseover=\"this.style.color='#003399';this.style.cursor='default';this.style.cursor='hand';this.style.textDecoration='underline'\"onmouseout=\"this.style.color='#000000';this.style.textDecoration='none'\" onclick=\"rc(" + x + "," + y + "," + level + "," + scale + "," + childId + ")\">" + childTitle + "</div>" +
"</div>";
var childNode2 = document.createElement("div");
childNode2.innerHTML = bb;
anchor.parentNode.insertBefore(childNode2,removeTextNode(anchorUp[i])); childNode.innerHTML = aa;
anchor.parentNode.insertBefore(childNode,removeTextNode(anchorUp[i]));
anchor.parentNode.removeChild(anchor.parentNode.childNodes[i + 2]) }
}
}
能说的详细些吗?