一旦我在某事上单击任何东西,便会告诉某事使之消失 [英] A script that tells something to disappaer once I click outside of it on anything
问题描述
好吧,我的网站上有一个表单搜索,当单击该表单时,会将搜索结果加载到显示的隐藏iframe中.这是iframe:
Okay I have a form search on my site that when clicked loads the search results into a hidden iframe that shows. This is the iframe:
<iframe class="slidingDiv" id="frame-content-left2" name="search-box"
src="content.html"></iframe>
这是用于切换显示状态的按钮:
This is the button that toggles it show state on/off:
<input type="submit" value="Search" class="send-button" />
现在,当上述iframe显示的是带有网站导航链接加载到的页面内容的div时,就会消失.这是div:
Now when the above iframe shows the div with page content that the site's navigation links load into disappears. This is the div:
<div id="myDiv">some content here</div>
现在我有一个问题,因为当我单击左侧的导航时,由于隐藏而无法看到加载到的div.我想要的是以某种方式告诉iframe及其搜索结果,一旦我在链接或空白区域之类的东西上单击以使其消失,则该div将消失:
Now I have a bit of problem because when I click on the navigations on the left you can't see the div that it is loaded into because it is hidden. What I want is to somehow tell the iframe with the search results to disappear once I click outside of it on something, like a link or blank area, making this div:
<div id="myDiv">some content here</div>
重新出现.
这是我正在使用的代码:
This is the code that I am using:
<script type="text/javascript">
$(document).ready(function() {
$('.send-button').click(function() {
if ($('#frame-content-left2').is(':visible')) {
$('#frame-content-left2').hide(2000);
$('#myDiv').show(2000);
}
else {
$('#frame-content-left2').show(2000);
$('#myDiv').hide(2000);
}
});
});
推荐答案
将单击侦听器附加到文档,并查看事件的目标.如果目标是应该使div出现的东西,则使它出现.
Attach a click listener to the document and look at the target for the event. If the target is something that should make the div appear, make it appear.
$(document).click(function(e){
if(e.target.id !== 'myDiv'){
$('#myDiv').show();
}
});
某种程度的事情将执行您想要的操作.
Something to that extent will perform the action you're looking for.
这篇关于一旦我在某事上单击任何东西,便会告诉某事使之消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!