从函数中分离preventDefault()

Lou*_*uis 3 jquery

而不是像这样的东西

$('#submitbutton').click(function(e) {
    e.preventDefault(); //to avoid the submit button to reload the page and go page to page one.
/* computing dimensions */
});
Run Code Online (Sandbox Code Playgroud)

我想把我的功能放在其他地方,比如:

$('#submitbutton').click(computeUserDimensions);

function computeUserDimensions(){
/* computing dimensions */
}
Run Code Online (Sandbox Code Playgroud)

但后来我不在哪里preventDefault提供点击(在提交按钮上)转到另一个页面.

你能帮我搞清楚吗?

谢谢

Adi*_*dil 5

将参数添加event到函数中,它将被jQuery隐式传递.

$('#submitbutton').click(computeUserDimensions);

function computeUserDimensions(event){
    /* computing dimensions */
    event.preventDefault();
}
Run Code Online (Sandbox Code Playgroud)