在Angular JS中将其隐藏在其范围之外时隐藏div [英] Hide a div when clikced outside its scope in Angular JS
本文介绍了在Angular JS中将其隐藏在其范围之外时隐藏div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我点击一个按钮时,会显示一个div,我想要做的就是当我在窗口的任何地方点击它时想隐藏它。
我不能使用JQuery。必须找到一种角度方法。想写一个自定义指令..
任何建议??
我发现这个网站网站
但是因为我是Angular am的新手没有完全理解
谢谢
Hi,
When i click a button a div is shown and what i want to do is when i click outside it anywhere in window wants to hide it.
I cannot use JQuery . Must find a way to do in angular. Thought of writing a custom directive ..
Any suggestions ??
I found this site Site
but since am new to Angular am not fully getting the idea
Thanks
推荐答案
这里是hide和show div的示例
i创建两个div
按钮点击我显示一个div并隐藏第二个div
on windows mouseout event hide div
还有鼠标在div上隐藏div本身
< br $>
< title>新文件
function show(id)
{
// alert(id)
document.getElementById(dv)。style.visibility =可见;
document.getElementById(dv1)。style.visibility =hidden;
}
函数hide(id){
document.getElementById(id).style.visibility =hidden;
document.getElementById(dv1)。style.visibility =visible;
}
show1
show2
here is sample of hide and show div
i have create two div
on button click i have show one div and hide 2nd div
on windows mouseout event hide div
also mouseout on div hide the div itself
<title> New Document
function show(id)
{
//alert(id)
document.getElementById("dv").style.visibility = "visible";
document.getElementById("dv1").style.visibility = "hidden";
}
function hide(id) {
document.getElementById(id).style.visibility = "hidden";
document.getElementById("dv1").style.visibility = "visible";
}
show1
show2
使用此代码
Use this code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
<script type="text/javascript">
var flgIsHide = false;
function controller1(
范围){
这篇关于在Angular JS中将其隐藏在其范围之外时隐藏div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文