每次我尝试使用confirm()命令时,都说确认未定义。重要的是要注意,我正在Atom.io IDE编程,并且我正在使用脚本软件包来编译和运行我的程序。这是我要运行的程序:
if ("atom".length >= 6)
{
console.log("The statement is true")
}
else
{
confirm("The statement is false")
}
Atom的脚本软件包不使用DOM或浏览器API运行JS,包括alert
和confirm
,甚至window
。您应该从浏览器中运行脚本。
在此stacksnippet中运行它,应该没关系:
if ("atom".length >= 6)
{
console.log("The statement is true")
}
else
{
confirm("The statement is false")
}
原子API提供atom.confirm()
,请参阅文档有关详细信息。
示例:
atom.confirm({
message: 'How you feeling?',
detailedMessage: 'Be honest.',
buttons: {
Good: function() {
return window.alert('good to hear');
},
Bad: function() {
return window.alert('bummer');
}
}
});