我正在编写一个主要使用服务器端代码的应用程序。但无论何时连接正确,都会抛出错误。请帮忙。
function checkConnection() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
if (states[networkState]="Unknown connection")
{
alert('Get in a trusted Connection: ' + states[networkState]);
}
else if (states[networkState]="No network connection")
{
alert('Warning: ' + states[networkState]+': Please Get Connection and Reconnect');
}
else
{
var ref = window.open('http://70.61.212.124:8083', '_self', 'location=no');
}
}
答案 0 :(得分:1)
在你的陈述中
if (states[networkState]="Unknown connection")
{
alert('Get in a trusted Connection: ' + states[networkState]);
}
您正在分配
states[networkState]="Unknown connection"
所以
的价值 states[networkState]
始终为"Unknown connection"
,此if
条件始终为true,因为赋值始终返回true。
我希望你真正想做的是
states[networkState]=="Unknown connection"