代码仅在控制台中运行

时间:2015-11-22 03:08:26

标签: javascript

我的代码似乎只在控制台中运行,但是...此代码在页面加载后部署。 (你手动加载..书签..) 然而当我放入浏览器时...... javascript :(这里的代码) 什么都没发生。如果我去控制台,它会广播警报。 (测试目的)

function addServer() {
if (localStorage.server1 == 0) {
alert("moo");
} else {

}



}

function removeServer() {

}


// Detect if on server page or not... Server page has id tabs. List does not.

localStorage.setItem("server1", "0")
addServer();

1 个答案:

答案 0 :(得分:0)

尝试删除注释(它可能会注释掉它之后的所有行,因为整个代码在一行上运行)并在函数声明后添加分号:

function addServer() {
if (localStorage.server1 == 0) {
alert("moo");
} else {

}



};

function removeServer() {

};



localStorage.setItem("server1", "0");
addServer();
相关问题