gpt4 book ai didi

javascript - Chrome 抛出 Firefox 上不存在的 Javascript 错误,这完全破坏了 Javascript 代码?

转载 作者:行者123 更新时间:2023-11-28 19:58:56 25 4
gpt4 key购买 nike

我正在使用Vex.js (如果有帮助的话,它使用 jquery)为我的网站设置一些模式对话。我将脚本链接到页面并使用 getElementById(我被告知这是最佳实践)来注册将弹出对话框的按钮单击。在 FF 中一切正常,但在 Chrome 上根本不起作用,当我检查控制台时,我得到 Uncaught SyntaxError: Unexpected identifier在第 1 行第 1 栏。

我的代码如下所示:

function popup() vex.dialog.open({
message: 'Enter your username and password:',
input: "",
buttons: [
$.extend({}, vex.dialog.buttons.NO, {
text: 'Login'
})
],
callback: function(data) {
if (data === false) {
return console.log('Cancelled');
}
return console.log('Username', data.username, 'Password', data.password);
}
});


document.getElementById("sharebutton").onclick = popup;

谢谢。

最佳答案

正如@Jason P建议的那样,使用花括号:

function popup() {
vex.dialog.open({
message: 'Enter your username and password:',
input: "",
buttons: [
$.extend({}, vex.dialog.buttons.NO, {
text: 'Login'
})
],
callback: function(data) {
if (data === false) {
return console.log('Cancelled');
}
return console.log('Username', data.username, 'Password', data.password);
}
});
}

document.getElementById("sharebutton").onclick = popup;

关于javascript - Chrome 抛出 Firefox 上不存在的 Javascript 错误,这完全破坏了 Javascript 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22025867/

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