Javascript点击< body> - 警报 [英] Javascript click on <body> - Alert
问题描述
我有这个之类的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点击< body> - 警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!