Javascript点击< body> - 警报 [英] Javascript click on <body> - Alert

查看:104
本文介绍了Javascript点击< body> - 警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个之类的JavaScript,现在我想添加一个功能来改进它。我想添加的功能,将点击正文,但不是在红点,提醒用户。

I have have JavaScript like this and I now want to add one more function to improve it. I want to add function that will on click on body but not on red dot, alert user.

- 完全当用户点击RED DOT功能不会提醒他,但是如果他错过了RED DOT脚本将会提醒他。这将看起来:如果< body> 被点击,但.a不alert(Error);非常感谢。我已经搜索了它,但没有结果。

-Exactly When User click on RED DOT function won't alert him, but if he miss RED DOT script will alert him. Thats will look: If <body> is clicked but .a not alert("Error"); Thanks a lot. I have googled for it but no results.

推荐答案

您需要将事件侦听器绑定到主体,确保目标不是 .a div。使用如下所示:

You need to bind the event listener to the body, making sure that the target is not the .a div. Use something like this:

$("body").click(function (event) {
  if(event.target != $('div.a')[0])
    alert('You clicked the body!');
});

这篇关于Javascript点击&lt; body&gt; - 警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆