相关疑难解决方法(0)

如何检测元素外部的单击?

我有一些HTML菜单,当用户点击这些菜单的头部时,我会完全显示.当用户点击菜单区域外时,我想隐藏这些元素.

jQuery可以这样吗?

$("#menuscontainer").clickOutsideThisElement(function() {
    // Hide the menus
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery

2367
推荐指数
35
解决办法
116万
查看次数

jQuery` .is(":visible")`不在Chrome中工作

if ($("#makespan").is(":visible") == true) { 
    var make = $("#make").val(); 
}
else {
    var make = $("#othermake").val(); 
}

Make:<span id=makespan><select id=make></select><span id=othermakebutton class=txtbutton>Other?</span></span><span id=othermakespan style="display: none;"><input type=text name=othermake id=othermake>&nbsp;-&nbsp;<span id=othermakecancel class=txtbutton>Cancel</span></span>
Run Code Online (Sandbox Code Playgroud)

上面的代码在Firefox中运行顺畅,但在Chrome中似乎不起作用.在Chrome中它.is(":visible") = false甚至可以显示true.

我正在使用以下jQuery版本:jquery-1.4.3.min.js

jsFiddle链接:http://jsfiddle.net/WJU2r/4/

jquery google-chrome

204
推荐指数
7
解决办法
53万
查看次数

jQuery:在元素的任何其他位置单击时隐藏元素

可能重复:
如何检测元素外部的单击?

div如果用户点击除元素之外的任何地方,我正试图实现隐藏.toggle()如果用户点击按钮,我会得到以下代码.如果Details元素可见,我希望按钮单击保持加号,对屏幕的其他部分做出反应.

$('.nav-toggle').click(function() {
  //get collapse content selector
  var collapse_content_selector = $(this).attr('href');

  //make the collapse content to be shown or hide
  var toggle_switch = $(this);
  $(collapse_content_selector).toggle(function() {
    if ($(this).css('display') == 'none') {
      //change the button label to be 'Show'
      toggle_switch.html('Show Details');
    } else {
      //change the button label to be 'Hide'
      toggle_switch.html('Hide Details');
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery

43
推荐指数
1
解决办法
2万
查看次数

标签 统计

jquery ×3

javascript ×2

google-chrome ×1