自定义点击功能之前执行默认事件 [英] Execute default event before custom click function

查看:73
本文介绍了自定义点击功能之前执行默认事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行按钮的默认事件,然后再执行自定义功能

I'm trying to execute the default event of a button before executing my custom function

我的代码:

$('#Button').click( function (){
    sideMenuCheck();
});

我不希望在函数的默认事件之后执行此操作 像这样:

I wan't this to be executed after the default event of the function Like this:

$('#Button').click( function (){
    **event.default();**
    sideMenuCheck();
}); 

但是我没有找到任何解决方案.

but I didn't find any solution.

不重要

之所以这样做,是因为我有一个不带画布的菜单,并且菜单在打开后必须具有可见的高度,(#Button)是从侧面打开菜单的按钮.

I'm doing this because I have an off-canvas menu, and menu has to be with the visible height after it opens, (#Button) is the button that opens menu from the side.

推荐答案

您可以将代码包装在setTimeout中,并且超时时间为0-这将导致代码将代码移至执行的底部排队,并允许其他所有内容先运行:

You can wrap up your code in a setTimeout with a timeout of 0 - this will cause it to move your code to the bottom of the execution queue, and allow everything else to run first:

$('#Button').click( function (){
    window.setTimeout(function() {
        sideMenuCheck();
    }, 0);
}); 

这篇关于自定义点击功能之前执行默认事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆