我正在尝试使用地图编号用选定数组中的值填充声明的HTML数据列表。我在表单上有一个操作按钮,JavaScript是一个函数。它可以在FireFox中完美运行,并在所选地图的数组中返回声明。 Chrome提供了错误的声明数据列表。
选择Map 2在FireFox中给出正确的列表:Ceedee#1和Ceedee#2。 Chrome给出了Ceedee#1和Ceedee#2,还给出了Map 3的前三个声明。在Chrome中选择Map 1给出了Map 1的声明,也给出了Map 3的前两个声明,以及Map 2的第一个声明。在正确的声明之后显示在列表中。 这是Windows10。感谢您的帮助!
<!--HTML form for the map selection, function button, and claims list:-->
<div class="formRow">
<label for="theMap">The claim was on which map? *</label>
<fieldset>
<input name="map" id="theMap" type="text" placeholder="Select Map Number" required list="mapList" />
<datalist id="mapList">
<option value="1" >
<option value="2" >
<option value="3" >
</datalist>
</fieldset>
</div>
<div class="claimRow">
<fieldset>
<input type="button" name="findClaims" value="After selecting a map, click to get the claims list for the map" onclick="getClaims(this.form)">
</fieldset>
</div>
<div class="claimRow">
<label for="theClaim">Which claim did you visit?</label>
<fieldset>
<input name="claim" id="theClaim" type="text" placeholder="Select claim name" list="claimsList" />
<datalist id="claimsList" >
</datalist>
</fieldset>
</div>
<script>
function getClaims (form) { // Runs when the button is pushed on the form
var str=''; // variable to store the options
var claimsArray = new Array();
var map1 = new Array("Caitlin", "Roadrunner", "More Values");
claimsArray.push(map1);
var map2 = new Array("Ceedee #1", "Ceedee#2");
claimsArray.push(map2);
var map3 = new Array("Happy Times", "Jacks Hideaway", "Renee's Best Chance", "Saddle Traps");
claimsArray.push(map3);
var claim = claimVisit.theMap.value;
--claim; // change the map number to an index value
for (var i=0; i < claimsArray[claim].length;++i){
str += '<option value="'+claimsArray[claim][i]+'" />'; // Storing options in variable
}
var my_list=document.getElementById("claimsList");
my_list.innerHTML = str;
}
</script>
答案 0 :(得分:0)
var claim = theMap.value;
claimVisit在这里不使用。足够的ID