Jquery 我怎样才能得到;。是";在旧版本的Internet Explorer中工作
我不能让“.is”工作。它在IE9、firefox和其他现代浏览器中工作得很好,但在IE8或IE7中却不行Jquery 我怎样才能得到;。是";在旧版本的Internet Explorer中工作,jquery,internet-explorer-8,internet-explorer-7,hover,Jquery,Internet Explorer 8,Internet Explorer 7,Hover,我不能让“.is”工作。它在IE9、firefox和其他现代浏览器中工作得很好,但在IE8或IE7中却不行 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script src="https://ajax.googleap
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$('body').click(function () {
if (!$('.myDiv').is(":hover")) {
alert("outside of blue div");
}
});
</script>
<div class="myDiv" style="width:150px; height:150px; background:blue"> </div>
</body>
</html>
$('body')。单击(函数(){
如果(!$('.myDiv')。是(“:hover”)){
警报(“蓝色分区外”);
}
});
或者看看这里
如何使其在IE8及更早版本中工作?尝试使用$(文档)。单击而不是$(“正文”)。单击。有时
标记不占用全屏高度/宽度,因此您可能会在
标记之外单击
另外,请尝试使用,而不是。is(“:hover”)
$(e.target).is('.myDiv')
$(e.target).最近('.myDiv')。长度===0
(.closest
用于检测我们是否正在单击div或div的子级)。我认为IE7或IE8不支持:hover
CSS伪属性
$(document).click(function(e) {
if($(e.target).closest('.myDiv').length === 0) {
alert("outside of blue div");
}
});
演示:
更多测试:
更新的演示:谢谢,但问题是如果我点击div中的某个内容,就会触发警报。下面是一个示例(尝试klicking文本):@user263091:Changeif(!$(e.target).is('.myDiv')){
到if($(e.target).最近('.myDiv')。长度==0){