Php jquery not运算符:无法隐藏div
我不熟悉jquery。如果单击其他id,我试图隐藏getLocation div。 但这不起作用Php jquery not运算符:无法隐藏div,php,jquery,Php,Jquery,我不熟悉jquery。如果单击其他id,我试图隐藏getLocation div。 但这不起作用 $(:not("#getLocation")).click(function(){ if($("#getLocation").show()==true){ $("#getLocation").hide(); } }); 试试这个: $('*:not("#getLocation")').click(function(){ $("#getLocation").toggle();
$(:not("#getLocation")).click(function(){
if($("#getLocation").show()==true){
$("#getLocation").hide();
}
});
试试这个:
$('*:not("#getLocation")').click(function(){
$("#getLocation").toggle();
});
$(document).click(function (e)
{
var container = $("YOUR CONTAINER SELECTOR");
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
{
container.hide();
}
});
仅语法错误
$('*:not(“#getLocation”)=>将返回除id=getLocation的元素之外的所有元素
if($(“#getLocation”).show()==true){
永远不会是真的,因为它是一个对象
jQuery在每次getter操作后返回元素的对象
它是对象链接
例如,如果您有一个id为myDiv
然后,您可以在一条语句中执行三个操作,如下所示:
$("#myDiv").show().css('color', 'red').css('padding', '12px 12px 12px 12px');
在这里,在show()
元素之后,返回该元素的一个对象
再次更改css,再次返回一个对象
使用jQuery
更正代码:
$(':not(#getLocation)').click(function(){
$("#getLocation").toggle();
});
试试这个代码
$("#getLocation").click(function(){
$("#getLocation").addClass("hide");
});
使用以下命令:
$('#getLocation').on('click', function(){
var target = $(this).attr('rel');
$("#getLocation"+target).show().siblings("div").hide();
});
您可以使用
event.target
筛选出相关div,如下所示:
<div id="a">
Div 1
</div>
<div id="b">
Div 2
</div>
<div id="getLocation">
Hide/show
</div>
您可能需要这个
$(document).not($("#getLocation")[0]).click(function(){
if($("#getLocation").is(':visible')){
$("#getLocation").hide();
}
});
您可以像通常用于导航菜单一样使用容器逻辑。例如,如果您在div外部单击,则div将隐藏 试试这个:
$('*:not("#getLocation")').click(function(){
$("#getLocation").toggle();
});
$(document).click(function (e)
{
var container = $("YOUR CONTAINER SELECTOR");
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
{
container.hide();
}
});
希望这对您有所帮助!在您单击的div/元素上,编写类似
$(“#element_id”)。单击(函数(){};
$(“#getLocation”)。切换()$(:not(“#getLocation”))
您到底想实现什么?$(“#element_id”)。单击(函数(){$(“#getLocation”)。隐藏());此not运算符: