【发布时间】:2017-01-22 06:24:24
【问题描述】:
我有一个网页,我在其中定义了一个 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>
【问题讨论】:
-
onBlur 事件是否可以与 DIV 元素一起使用?我认为它不起作用。
标签: javascript jquery html ajax dom