Bootstrap 按钮点击无效

Bootstrap button onclick not working

我有一个使用 EJS 的 node express 应用程序。

我有一个按钮:

<button type="button" class="btn btn-success" onclick="exportWithObjectId('<%= user.id %>')">Export to csv</button>

和一个脚本:

<script type="text/javascript">

    function exportWithObjectId(objectId) {

        console.log("objectID inside .ejs: " + objectId);
    }
</script>

在我的 .ejs 文件中,但是当我单击时没有日志。知道我做错了什么吗?

从函数调用中删除 document.

onclick="exportWithObjectId('<%= user.id %>')">

或者,将其替换为 window.:

onclick="window.exportWithObjectId('<%= user.id %>')">

示例:

function exportWithObjectId(objectId) {
  console.log("objectID inside .ejs: " + objectId);
  alert('Just to be sure! objectID inside .ejs: ' + objectId);
}
<button type="button" class="btn btn-success" onclick="exportWithObjectId('<%= user.id %>')">Export to csv</button>