Html 如何在div上模拟onblur事件

Html 如何在div上模拟onblur事件,html,Html,在代码示例中,单击两个div会使背景色变为灰色 再次单击第一个div(内容可编辑)将颜色更改回白色。单击第二个div(不可编辑内容)不会更改 有没有一种方法可以轻松地为第二个div获得相同的结果 <div contenteditable="true" style="width:100px; height:100px; border: 1px solid red;" onclick="this.style.backgroundColor='gray'" onblur="this.style.

在代码示例中,单击两个div会使背景色变为灰色

再次单击第一个div(内容可编辑)将颜色更改回白色。单击第二个div(不可编辑内容)不会更改

有没有一种方法可以轻松地为第二个div获得相同的结果

<div contenteditable="true" style="width:100px; height:100px; border: 1px solid red;" onclick="this.style.backgroundColor='gray'" onblur="this.style.backgroundColor='white'"></div>

<div style="width:100px; height:100px; border: 1px solid blue;" onclick="this.style.backgroundColor='gray'" onblur="this.style.backgroundColor='white'"></div> 


我不确定是否有一种方法可以精确地模拟模糊。。。我将使用与此类似的jQuery函数

例如:

$(文档).mouseup(函数(e)
{
变量容器=$(“.noteditable”);
if(!container.is(e.target)//如果单击的目标不是容器。。。
&&container.has(e.target).length==0)/…或容器的后代
{
css('background-color','white');
}
});


我会检查单击的元素是否为div。。。这里有一个类似的情况:我最后向文档体添加了一个事件侦听器,它将更改onmousedown的背景色。谢谢你的帖子。我最后在文档正文中添加了一个事件侦听器,它将更改onmousedown的背景色。谢谢你的帖子。