首先,我现在已经广泛阅读了关于如何在正确检测到div外的点击或事件之后隐藏div的经常性问题;的确,这影响了我的JavaScript代码。但我是一个新手,它不工作,所以我希望你能帮助我。jquery隐藏并显示一个按钮
二,jfiddle - https://jsfiddle.net/u5uzexqk/ ...请注意,按钮应显示当搜索栏的任何部分或确实按钮被点击;并且当检测到外部任何地方的点击时不显示。
之前的代码,我只想指出,我也读过电子传播的事情,但我不认为这是缺乏这是什么问题;如果是这样的话,我非常抱歉。也许由于我是Javascript新手,我看不出来自其他问题的建议答案如何帮助;最常见的答案Jfiddle似乎做了相反的事情 - 当菜单链接再次被点击时删除菜单。
的Html
<body>
<div id = "wrapper">
<form action="" class="search-form">
<div class="cell">
<input type="text" name="q">
</div>
<div class="cell button-holder">
<button type="submit" id="dropdownbutton">
<span>Search</span>
</button>
</div>
</form>
</div>
</body>
的Javascript
$("#wrapper").onclick(function (e){
document.getElementById('#dropdownbutton').style.visibility = 'visible';
}
$(document).mouseup(function (e)
{
var container = $("#wrapper");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
$("#dropdownbutton").hide();
}
});
});
因此,例如一半的JavaScript从这个有用的职位后来(在某些方面) - http://stackoverflow.com/questions/1403615/use-jquery-to-hide-a-div-when-the-user-clicks-outside-of-i t – user1849962
对不起,你是说这应该被标记 - java? – user1849962
现在排序,我希望 – user1849962