子节点在父节点中的位置

phpxiaoxin 2008-05-15 07:35:48
在做一个文件上传的东西,想动态添加上传文件的输入点已经没问题,现在就是想删除节点,想请教一下,如何在知道子节点的情况下,得到其在父节点中的定位,然后将其删除,有没有类似java的indexof的方法?

谢谢各位。

<div id="appendBuildPic"><div>标    题:<input type="text" name="pictureName" id="pictureName" maxlength="20" /> 图    片:<input type="FILE" name="picturePath" id="picturePath" /> <input type="button" onClick="deleteCurrentRow1(this)" value="删除" /></div></div>
<script language="javascript">
function add(obj){
parents = getObj("appendBuildPic")
allNodes = parents.childNodes;
var allNodeSize = allNodes.length;
if (allNodeSize>=3){
alert("最多允许添加三个");
}
if (allNodeSize<3){
var divs = document.createElement("div");
divs.innerHTML = "标    题:<input type=\"text\" name=\"pictureName\" id=\"pictureName\" maxlength=\"20\" /> 图    片:<input type=\"FILE\" name=\"picturePath\" id=\"picturePath\" /> <input type=\"button\" onClick=\"deleteCurrentRow1(this)\" value=\"删除\" />";
getObj("appendBuildPic").appendChild(divs);
obj.rel = parseInt(size)+1;
}
}
function deleteCurrentRow1(nodePosition){
this.parentNode;
parents = getObj("appendBuildPic")
allNodes = parents.childNodes;
var allNodeSize = allNodes.length;
for(var i = 0; i <= allNodeSize; i++) {
thisNode = allNodes[i];
alert(thisNode);
parents.removeChild(thisNode);
}
}
</script>
...全文
152 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
myvicy 2008-05-16
  • 打赏
  • 举报
回复
^_^
s_liangchao1s 2008-05-16
  • 打赏
  • 举报
回复

ooooooooooooooooooooo

whetu 2008-05-16
  • 打赏
  • 举报
回复
=.=|||
浴火_凤凰 2008-05-15
  • 打赏
  • 举报
回复
学习......
phpxiaoxin 2008-05-15
  • 打赏
  • 举报
回复
不好意思各位,犯了一个低级错误,哎,
我已经有了子节点所在的位置,直接用父节点删除就可以了,干么非的找他的位置然后再循环呀,
代码如下:

function deleteCurrentRow1(nodePosition){
var father = nodePosition.parentNode;
var grandfather = nodePosition.parentNode.parentNode;
grandfather.removeChild(father);
}
这样调用:

<div id="upfiles">
<div><input type="file" name="uppic" /><input type="button" onclick="deleteCurrentRow1(this)" /></div>
<div><input type="file" name="uppic" /><input type="button" onclick="deleteCurrentRow1(this)" /></div>
<div><input type="file" name="uppic" /><input type="button" onclick="deleteCurrentRow1(this)" /></div>
<div><input type="file" name="uppic" /><input type="button" onclick="deleteCurrentRow1(this)" /></div>
</div>

87,899

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧