给定以下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>
我有以下javascript:
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"); }
}
问题:为什么根据localStorage中存储的值在加载页面时没有选择select标签的选项?提前致谢