想把JS的匿名函数改为普通函数,求助如何传递参数

现在有类似这样的代码

mui(document).on("tap", ".delete", function() {    console.log('mui(document).on("tap", ".delete")');
    commentId = this.getAttribute('comment-id');    console.log(commentId);
    deleteLetterComment(commentId);
});

我想把这里面的function提出来复用。我知道可以这么写

mui(document).on("tap", ".delete", beforeDeleteLetterComment);function beforeDeleteLetterComment() {    console.log('mui(document).on("tap", ".delete")');
    commentId = this.getAttribute('comment-id');    console.log(commentId);
    deleteLetterComment(commentId);
}

然而还有一段代码需要传递参数

function beforesubmitComment(str){

}

我想也这样用,但是直接写mui(document).on("tap",".delete",beforesubmitComment(str));不生效

求助该怎么写。


慕少森
浏览 991回答 1
1回答

三国纷争

mui(document).on("tap",".delete",function(){     beforesubmitComment(str) });
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript