简体   繁体   English

下拉列表模糊事件

[英]Dropdown list blur event

I am building a dropdown list of anchor tags (not a select): 我正在构建锚标记的下拉列表(不是选择项):

<ul>
  <li class="selected"><a href="#">List item 1</a></li>
  <li><a href="#">List item 2</a></li>
  <li><a href="#">List item 3</a></li>
  <li><a href="#">List item 4</a></li>
</ul>

When a user selected the list, it triggers a focus state which shows all items. 当用户选择列表时,它将触发显示所有项目的焦点状态。 I also want it to blur when the user clicks off of the ul or selects an item. 当用户单击ul或选择一个项目时,我也希望它模糊

Is this possible? 这可能吗?

Note: .blur() and .focus() only work with form elements. 注意: .blur().focus()仅适用于表单元素。

Try using mouseleave() event 尝试使用mouseleave()事件

$( "ul" ).mouseleave(function() {
     //console.log('similar to blur');
});

I have just .toggle() for my dropdown 我的下拉菜单只有.toggle()

function DropDownMenu() {
  var item1 = document.getElementById("dropdownmenu1");
     $("#dropdownmenu1").toggle();
 }

, this is when I click on the dropdown. ,这是我单击下拉列表时的时间。 If I click elsewhere on the page, I have this; 如果我单击页面上的其他位置,则显示此内容。

function BlurDropDown() {
    $("#dropdownmenu1").fadeOut(1000);
}

And on my div for the rest of the page, I have set a onmousedown event 在页面的其余部分的div上,我设置了一个onmousedown事件

    <div id="page" onmousedown="BlurDropDown()">

My menu is placed on the master page. 我的菜单位于母版页上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM