Cordova Phonegap-选择选项“;精选;通过JavaScript

Cordova Phonegap-选择选项“;精选;通过JavaScript,cordova,selection,local-storage,Cordova,Selection,Local Storage,给出以下html代码: <body onload="loadSett()"> <form id="settingsForm" name="settingsForm"> <select name="Sound" id="Sound"> <option value="0">Off</option> <option value="1">On</option> </s

给出以下html代码:

<body onload="loadSett()">
<form id="settingsForm" name="settingsForm">
    <select name="Sound" id="Sound">
        <option value="0">Off</option>
        <option value="1">On</option>
    </select>

    <select name="Vibration" id="Vibration">
        <option value="0">Off</option>
        <option value="1">On</option>
    </select>
</form>
</body>

问题:为什么选择标记的选项在根据本地存储中存储的值加载页面时未被选中?提前感谢

您的代码基础没有问题。可能会检查控制台输出是否有错误等


下面是一个jsbin版本的代码,它可以正常工作:

我已经检查了localstorage,它的值0表示“声音”,1表示“振动”。。。但在加载页面时,两个都是“关闭”的,即0
var getSound;
var getVibra;

function loadSett() {
    var form = $("#settingsForm");
    getSound = localStorage.getItem("sound");
    getVibra = localStorage.getItem("vibra");

    if(getSound != undefined && getVibra != undefined) {
        if(getSound == "1"){
            document.getElementById('Sound').options[1].selected = true;
        }
        if(getVibra == "1"){
            document.getElementById('Vibration').options[1].selected = true;
        }
    } else { alert("Empty"); }
}