gpt4 book ai didi

jquery - 窗口未定义,文档未定义- Electron

转载 作者:行者123 更新时间:2023-12-03 12:35:27 28 4
gpt4 key购买 nike

我正在开发一个应用程序,并尝试主要使用jquery,我已经在线尝试了所有示例,但是我似乎无法弄清我的错误所在。请有人可以查看我的代码并告诉我我做错了..
这是我的代码。

const {app, document, BrowserWindow, Menu} = require('electron')
const path = require('path')
const url = require('url')

//define jquery..
window.$ = require('jquery')(window);

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win

function createWindow () {
// Create the browser window.
win = new BrowserWindow({
name:"AtikuDesk",
width: 396,
height: 356,
frame:false,
transparent: true,
toolbar: false
});

// and load the index.html of the app.
win.loadFile('assets/index.html')

// Open the DevTools.
win.webContents.openDevTools()

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})

menuarr = [
{
label:'Home',
submenu:[
{label:'About App'},
{label:'view statistics'},
{label:'get help'}
]
},
{
label:'Exit',
click(){
app.quit()
}

}

];

var menu = Menu.buildFromTemplate(menuarr);
Menu.setApplicationMenu(menu);


function clsApp(e){
app.quit();
}
$('#clsbtn').bind('click', clsApp);

最后一个函数不起作用,它不起作用,它显示错误的窗口未定义,并且当我尝试使用此代码时..没有Jquery的情况下,
document.querySelector('#clsbtn').addEventListener('click', clsApp)

它总是告诉我该文档是未定义的。我还无法在线找到合适的解决方案,如果有人帮助我解决该问题,我们将非常高兴。

我更喜欢处理来自单独javascript文件的所有事件和操作,而不是处理html页面上的内联脚本标签。

谢谢。

最佳答案

从主JS文件中删除此代码。然后在index.html中:

<script>window.$ = window.jQuery = require('jquery');</script>
<script src="index.js"></script>

和index.js:
function clsApp(e){
app.quit();
}
$('#clsbtn').bind('click', clsApp);

关于jquery - 窗口未定义,文档未定义- Electron ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50602004/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com