This article mainly shares with you a js method to close the menu outside the range of the drop-down menu when clicked. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.
The example is as follows:
$(function(){ $(document).bind("click",function(e){ //id为menu的是菜单 if($(e.target).closest("#menu").length == 0 && $(e.target).closest("input").length == 0){ //点击id为menu之外且id,则触发 hideMenu(); } }) })
Related recommendations:
ajax drop-down menu Cascade operation
jQuery implementation of drop-down menu method sharing
jQuery implementation of drop-down menu accordion effect sharing
The above is the detailed content of js closes the menu outside the range drop-down menu when clicked. For more information, please follow other related articles on the PHP Chinese website!