我已經閱讀了那個服務器端,你不能使用 DOM。我已經使用 DOM 創建了一個 Web 應用程式,我想知道需要做什么來重現此代碼以使其在服務器上作業,以便 Internet 上的人們可以使用它。這是代碼的一個小高峰:
// Listen for export button click
document.getElementById('exportForm').addEventListener('submit', function (e) {
setTimeout(exportData, 20);
e.preventDefault();
});
// Export data function
function exportData(e) {
console.log("Exporting...");
// device details and time range details
const devId = (document.getElementById('deviceInput')).value;
var dateFrom = (document.getElementById('dateFromInput')).value;
var dateTo = (document.getElementById('dateToInput')).value;
var timeFrom = (document.getElementById('timeFromInput')).value;
var timeTo = (document.getElementById('timeToInput')).value;
const limit = (document.getElementById('limitInput')).value;
const key = (document.getElementById('keysInput')).value;
當我嘗試使用 pm2 start app.js 在服務器上運行它時,它回傳此錯誤:
ReferenceError: document is not defined
at Object.<anonymous> (/home/cloud/sites/App/app.js:6:1)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
我聽說過 JSDom,但我認為字串中需要包含 html,然后我不知道如何在其中連接 css 等等。我有更好的方法來完成這項作業嗎?
uj5u.com熱心網友回復:
檔案物件是一種瀏覽器功能,因此您不能在服務器內部使用它,而是您具有其他功能,例如 FS(檔案系統)
無論如何使用 JSDo 都是可能的,你必須使用行內樣式重寫https://www.codecademy.com/article/html-inline-styles這不是一個好習慣,你應該避免它
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/452194.html
標籤:javascript html dom 服务器 pm2
