自动完成搜索建议下拉弹出 [英] auto-complete search suggestion drop-down popup

查看:136
本文介绍了自动完成搜索建议下拉弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着做一个弹出的div(当一个文本框值发生变化),它可以关闭:点击分区以外的任何地方(能见度无)。
类似谷歌建议下拉。

Im trying to make a popup div (when a text-box value changes) and it can be closed (visibility: none) by clicking anywhere outside the div. Similar to Google suggestion drop-down.

我怎么能知道度过鼠标点击发生在div内部还是外部。

How can I know weather the mouse click has happened inside the div or outside.

我要实现这个使用javascript和jsp。

I need to implement this using javascript and jsp.

请帮忙。

推荐答案

jQuery的解决方案将是

The jquery solution would be

$("body > div").click(function() {
if ($(this).attr("id") == "div-id") {
    // inside the DIV
} else {
    // not inside the DIV
}
});

$("html").click(function (e)
{
if (e.target == document.getElementById("div-id"))
    alert("Inside DIV");
else
    alert("Outside DIV!");
});

或Javascript代码段将是这样的:

or Javascript snippet would be something like this:

<script type="text/javascript"> 
document.onclick=check; 
function check(e){ 
var target = (e && e.target) || (event && event.srcElement); 
var obj = document.getElementById('div-id'); 
if(target!=obj){obj.style.display='none'} 
} 
</script>

这篇关于自动完成搜索建议下拉弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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