0
我使用下面這個函數來獲取Internet連接類型JavaScript函數只有在連接類型的警報沒有
function checkConnection() {
var networkState = navigator.network.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.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
這將提醒狀態:警報(「連接類型:」 +狀態[networkState]);
我需要做的是得到,如果狀態是狀態[Connection.NONE]
我試了一下,只提醒什麼:
if ((states[networkState]) = states[Connection.NONE]) {
alert('No internet connection here');
}
,但沒有奏效。
您是否複製粘貼代碼?因爲在if語句中只有一個「=」而不是「==」 –