如果没有网络,Jquery手机屏幕禁用提交按钮

时间:2013-03-07 09:25:26

标签: jquery cordova mobile

我试图在我的jquery移动应用上禁用我的提交按钮。我已经尝试了几天才能让它发挥作用。按钮不会启用或禁用。这是我尝试过的很多脚本之一

document.addEventListener("deviceready", onDeviceReady, false);


function onDeviceReady() {
    checkConnection();
}

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';


        if(networkState==Connection.UNKNOWN || networkState==Connection.NONE) {
            $('[type="submit"]').button('disable');
            $('[type="submit"]').button('refresh');

        } else {
            $('[type="submit"]').button('enable');
            $('[type="submit"]').button('refresh');


        }

`

2 个答案:

答案 0 :(得分:1)

不应该是这样的:

if(networkState==states.Connection.UNKNOWN || networkState==states.Connection.NONE) {
   //........... your code stuff..............//
}

答案 1 :(得分:0)

尝试拨打

mybutton.disabled = true