<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript">
function $(nodeId)
{
return document.getElementById(nodeId);
}
function removeMsg()
{
var nodeBtn = $("remove");//按钮
document.body.removeChild(nodeBtn); }
</script>
</head>
<body>
<div id="div1">
<div id="div2">
<input type="button" id="remove" value="删除它" onclick="removeMsg();" />
</div>
</div>
</body>
</html>如果没有div1和div2,按钮可以很顺利地删除,要是有的话,该怎么办???(用jquery实现也行)
<head>
<script type="text/javascript">
function $(nodeId)
{
return document.getElementById(nodeId);
}
function removeMsg()
{
var nodeBtn = $("remove");//按钮
document.body.removeChild(nodeBtn); }
</script>
</head>
<body>
<div id="div1">
<div id="div2">
<input type="button" id="remove" value="删除它" onclick="removeMsg();" />
</div>
</div>
</body>
</html>如果没有div1和div2,按钮可以很顺利地删除,要是有的话,该怎么办???(用jquery实现也行)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript">
function $(nodeId)
{
return document.getElementById(nodeId);
}
function removeMsg()
{
var nodeBtn = $("remove");//按钮 nodeBtn.parentNode.removeChild(nodeBtn);
}
</script>
</head>
<body>
<div id="div1">
<div id="div2">
<input type="button" id="remove" value="删除它" onclick="removeMsg();" />
</div>
</div>
</body>
</html>
该控件的 parentNode 总有的吧.
有了 parentNode 那 removeChild(按钮控件) 总可以了吧.