[英]How can I remove all child element of DIV element on onBlur event?
我有一个网页,我在其中定义了一个ID为“ selectedProduct”的DIV元素,现在,当我单击特定链接时,它将调用ajax请求,并用响应数据填充DIV元素。 但是我要求当onBlur事件发生在“ selectedProduct” DIV上时,它应该删除它的所有子元素。 我的代码如下:
<script type="text/javascript">
function getPage(event,id)
{
event.preventDefault();
var page = document.getElementById(id).id + ".html";
var dataString = page
$.ajax(
{
type: "POST",
url: page,
data: dataString,
cache: false,
success: function(result)
{
var result=result;
$("#selectedProduct").html(result);
// location.replace("index1.html");
}
});
}
function focOFF(id)
{
// I don't have any idea what code should i write here which can remove all child of DIV element....
}
</script>
<body>
<a href="#selectedProduct" style="text-decoration:none" id="solar_power_plant" target="new" onClick="getPage(event,this.id)" class="scroll">Solar Power Plant</a>
<div id="selectedProduct" onBlur="focOFF(this.id)">
</div>
</body>
使用以下解决方案获取所有子元素并将其删除,
function focOFF(id)
{
$( "#"+id ).children().remove();
}
在模糊函数中使用empty( )函数。 删除所选元素的所有子节点
function focOFF(id)
{
$('#'+id).empty();
}
document.getElementById(id).innerHTML = '';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.