jquery.dropdown.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* ============================================================
  2. * jquery.dropdown.js 下拉js
  3. * ============================================================ */
  4. !function($) {
  5. // 定义下拉开关
  6. var dropdownToggle = '.J_dropdown';
  7. $(document).off('click',dropdownToggle).on('click',dropdownToggle, function() {
  8. var $this = $(this), isActive;
  9. if ($this.is('.disabled, :disabled')) return;
  10. isActive = $this.hasClass('open');
  11. clearMenus();
  12. if (!isActive) {
  13. $this.css('position', 'relative');
  14. $this.toggleClass('open');
  15. // 点击网页空白区域隐藏下拉框
  16. $(document).on('click', function(e) {
  17. var target = $(e.target);
  18. if (target.closest(".J_dropdown").length == 0) {
  19. clearMenus();
  20. };
  21. });
  22. };
  23. });
  24. function clearMenus() {
  25. $(dropdownToggle).each(function() {
  26. $(this).removeClass('open');
  27. $(this).css('position', '');
  28. })
  29. }
  30. // 阻止事件冒泡 此注释lww添加
  31. /*$('.J_dropdown_menu').on('click', function(e) {
  32. e.stopPropagation();
  33. });*/
  34. }(window.jQuery);