当我尝试使用RemoveChild()删除我的一些子元素时.但抛出异常.我在下面附上了我的代码.
nodeName = doc.SelectSingleNode("//Equipment//DataCollections//EnabledIDs//MyID[@id='" + attrValue + "']");
// Found the nodeName successfully druing run time.
doc.DocumentElement.RemoveChild(nodeName);
// faild to Remove the node
Run Code Online (Sandbox Code Playgroud)
显示以下错误:
An unhandled exception of type 'System.ArgumentException' occurred in System.Xml.dll
Additional information: The node to be removed is not a child of this node.
Run Code Online (Sandbox Code Playgroud)
如何删除节点?
[更新]
使用VS2005和.NET 2.0.
我有这个HTML:
<body>
<div id="content-container" style="display:none">
<div>John</div>
</div>
<div id="verifying">
<div id="message">Verified</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
这个Javascript:
var body = document.body;
var signup = document.getElementById("content-container");
setTimeout(function(){
body.removeChild('verifying');
signup.style.display = "block";
}, 5000);
Run Code Online (Sandbox Code Playgroud)
我想在5秒后删除<div id="verifying">并显示<div id="content-container">,但由于某种原因它无法正常工作.知道为什么吗?我在页面加载后加载脚本,这不是问题.
我有一堆图像.这些图像都被添加到精灵容器中:
var container:Sprite = new Sprite();
container.addChild(img);//added in a loop
addChild(container);
Run Code Online (Sandbox Code Playgroud)
后来,当我遍历容器删除图像时,我说:
for(var i:int=0;i<container.numChildren;i++)
{
var currImg:Sprite = container.getChildAt(i) as Sprite;
container.removeChild(currImg);
}
Run Code Online (Sandbox Code Playgroud)
仅删除部分图像.如果我跟踪container.numChildren,我会得到正确数量的图像.有人有同样的问题吗?
谁能解释我如何删除下拉菜单中的第(0)个/(n)元素?
<select name="selectBox" id="selectBox">
<option value="option1">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
<option value="option4">option4</option>
</select>
Run Code Online (Sandbox Code Playgroud) 我尝试empty()一个div但排除一个特定的选择器.
什么我试过到目前为止:
$('.modal').find('.close').nextAll().empty();
$('.modal').find(':not(.close)').empty();
$('.modal').not('.close').empty();
$('.modal:not(.close)').empty();
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="modal">
<a href="#" class="close">Close</a>
...I've the need to be removed...
</div>
Run Code Online (Sandbox Code Playgroud) 我正在附加一个引用 at javascript 和样式表的子元素,但是当不再使用它时,我想再次删除它。
var head = document.getElementsByTagName('head')[0];
// We create the style
var style = document.createElement('link');
style.setAttribute("rel", "stylesheet");
style.setAttribute("type", "text/css");
style.setAttribute("href", '_css/style.'+app+'.css');
var script = document.createElement('script');
script.setAttribute("type", "text/javascript");
script.setAttribute("src", '_scripts/_js/script.'+app+'.js');
// And the append the style
head.appendChild(style);
head.appendChild(script);
Run Code Online (Sandbox Code Playgroud)
这就是我附加脚本的方式,它完美地工作..但我无法弄清楚如何从 HTML 中的 head 标签中再次删除标签。
有没有人知道如何再次从标题标签中删除标签..我一直在 Stackoverflow 周围搜索,但实际上似乎没有人有这种问题,但如果有人知道还有另一个问题可以回答这个问题,请告诉我..
这让我疯了.我正在注册多个mouseout事件,即使我正在使用removeEventListener()删除它们.我尝试了各种各样的变化.基本上,一旦mouseout事件发生,我想摆脱它,因为用户将翻阅不同的图像以查看大预览.它工作正常,但注册的多个事件让我感到震惊.
this.removeEventListener('mouseout', handler, false);
Run Code Online (Sandbox Code Playgroud)
没别的了.我不确定我在这里做什么.我似乎无法摆脱mouseout事件,他们只是继续打桩.
document.querySelector('.grid').addEventListener('mouseover',function(e) {
if (e.target.tagName==='IMG') {
var myElement=document.createElement('div');
myElement.className='preview';
e.target.parentNode.appendChild(myElement);
var handler = e.target.addEventListener('mouseout', function (d) {
var myNode = d.target.parentNode.querySelector('div.preview');
console.log(d.target.parentNode);
if (myNode) {
myNode.parentNode.removeChild(myNode);
}
this.removeEventListener('mouseout', handler, false);
});
} //
}, false); // addEventListener
Run Code Online (Sandbox Code Playgroud) 我有一个段落元素数组。当每个<p>元素被点击时,我希望该元素从 DOM 中删除。我编写的代码仅在元素由其 id 指定时才有效。我尝试使用this关键字,并循环遍历元素,但没有成功,如下面的代码所示。
我在这里做错了什么?我怎样才能克服它?
<div class="section" id='section2'>
<a name="section-two" href="#top">Section Two</a>
<p id='tester'>Text here <span><img src='images/remove.png' height='20px'/></span></p>
<p>Text here. <span><img src='images/remove.png' width='20px'/></span></p>
<p>Text here. <span><img src='images/remove.png' height='20px'/></span></p>
<p>Text here. <span><img src='images/remove.png' height='20px'/></span></p>
</div>
var section2 = document.getElementById('section2').getElementsByTagName('p');
for(var i = 0; i < section2.length; i++) {
section2[i].addEventListener('click', function() {
section2[i].parentNode.removeChild(section2[i]);
}, false);
}
Run Code Online (Sandbox Code Playgroud) 我有一堆同名的元素,我试图用 onchange 函数同时删除它们。
这是javascript:
<script type="text/javascript">
function removeoldAccounts() {
var e = document.getElementById("account_table")
var accounts = document.getElementsByName("extraaccounts");
e.removeChildren(accounts);
}
</script>
Run Code Online (Sandbox Code Playgroud)
(甚至不确定 removeChildren 是否是一个真正的命令)还有我的元素,我将 onchange 操作赋予:
<select id="piname" name="pi_name" onChange="removeoldAccounts" />
Run Code Online (Sandbox Code Playgroud)
我试图删除的元素:
<tbody id="account_table">
<tr>
<td>Account Number<span>*</span>:</td>
<td id="accounts">
<select id="accountnum" name="account_number">
<option value="5636745946254">5636745946254</option>
<option value="23164847322">23164847322</option>
</select>
</td>
<td>
<input type="hidden" id="theValue3" value="81">
<input type="button" value="Add More" onclick="addaccount()">
</td>
</tr>
<tr id="80" name="extraaccount">
<td>
<select id="80" name="account_number">
<option value="5636745946254">5636745946254</option>
<option value="23164847322">23164847322</option>
</select>
</td>
<td>
<input type="text" size="20" name="account_comment80">
</td>
<td>
<input …Run Code Online (Sandbox Code Playgroud) 下面的代码创建一个名为"circle"的MovieClip并检查它是否存在并通过removeChild()删除它; 它删除了圆圈,但[对象MovieClip]仍然存在.
如何检查孩子是否"在舞台上"或使用removeChild删除?
import flash.display.MovieClip;
import flash.events.MouseEvent;
var circle:MovieClip = new MovieClip();
circle.graphics.beginFill(0xFF794B);
circle.graphics.drawCircle(50, 50, 30);
circle.graphics.endFill();
addChild(circle);
circle.addEventListener(MouseEvent.CLICK, test);
function test(event:MouseEvent)
{
trace(circle);
if(circle)
{
trace("Called if Circle");
removeChild(circle);
}
trace(circle);
}
Run Code Online (Sandbox Code Playgroud)