隐藏在正文单击EXPT项目ID =某物
Hide on body click exept item id = something
如何隐藏菜单,除非用户单击了ID = 'menubutton'的元素?
$('body').click(function(event) {
$('#menu').hide();
});
使用 not() 选择器
$('body :not(#menubutton)').click(function(event) {
$('#menu').hide();
});
http://api.jquery.com/not-selector/
使用 target
元素。
$('body').click(function(event) {
// If the element clicked doesn't have the id "menubutton"
if ( $(event.target).attr( 'id' ) !== 'menubutton' ) {
$('#menu').hide();
}
});
$('body').click(function(event) {
// don't hide if the clicked element was #menubutton,
// or any element within #menubotton
if (!$(event.target).closest('#menubutton').length) {
$('#menu').hide();
}
});
$('body :not(div #menubutton)').click(function(event) {
$('#menu').hide();
});
jQuery Not()
not() 的选择器可能需要对你的情况进行一些更改
相关文章:
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- difference between '$(<%= DDL.ID %>) & $('
- 使用Javascript获取所选选项ID
- 根据id将json数组组合为一个json数组
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 对id以某个字符串开头的元素进行计数
- 如果元素's的ID以数字开头
- 通过id和class属性获取元素
- 检查变量是否大于某物,但不是未定义的
- 如果 PHP 响应等于某物,如何使 jQuery 警报
- 隐藏在正文单击EXPT项目ID =某物
- 猫鼬函数 - 查找某物等于某物的计数
- 如何获取所有以某物开头的HTML属性(属性名称,*不是*它们的值!
- 我该如何使用 jQuery 使某物循环 12 次
- 函数某物(标记值)
- 迭代条目列表,如果条目的文本与“某物”相对应,则调用append () html(使用jquery)
- Javascript在Delphi:[某物]不是一个函数
- 将构造函数赋值给某物是什么意思?
- PHP表单与…某物
- 如何拥有一个类,它是某物的属性