我有一个使用Javascript的HTML页面,它在IE中运行良好,但它在Firefox,Chrome或Safari中运行不佳。我的代码动态地将数据添加到IE中的下拉列表中,但我猜我的语法不适合FF,Chrome或Safari?在FF,Chrome,Safari中,下拉框仅显示硬编码值,并且永远不会在前面提到的3个浏览器中更新。假设我的阵列在FF或Chrome中正确填充,那么我猜我用于将数据添加回下拉框的方法是不是按照FF或Chrome的方式编写的?
<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.tasks.route");
dojo.require("esri.tasks.query");
var dynamicarray = [];
queryTask.execute(query, showResults);
function showResults(results) { //This is where I can add values to dropdown in IE
var featureAttributes;
var addoffices = document.getElementById("Office");
var addrigs = document.getElementById("Rigs");
for (var i = 0, il = results.features.length; i < il; i++) {
featureAttributes = results.features[i].attributes;
for (att in featureAttributes) {
dynamicarray.push(featureAttributes[att]);
if (isNaN(featureAttributes[att])) {
addrigs.options.add(new Option(featureAttributes[att], att));
}
if (isNaN(featureAttributes[att])) {
addoffices.options.add(new Option(featureAttributes[att], att));
}
}
}
}
function officeval() {
d = document.getElementById("Office");
var de = d.options[d.selectedIndex].text;
addStop(de);
}
function addStop(evt) {
var lat;
var lon;
var dar;
for (dar in dynamicarray) {
if (dynamicarray[dar] == evt) {
lon = dynamicarray[dar - 1]; //Get Longitude value
lat = dynamicarray[dar - 2]; //Get Latitude value
var inPoint = new esri.geometry.Point(lon, lat, map.spatialReference);
var stop = map.graphics.add(new esri.Graphic(inPoint, stopSymbol));
routeParams.stops.features.push(stop);
map.graphics.add(new esri.Graphic(new esri.geometry.Point(lon, lat, map.spatialReference), textSymbol));
break;
}
}
}
</script>
From:
<SELECT id="Office" SIZE=0 onchange="officeval()">
<OPTION VALUE="0">
<OPTION VALUE="1"> Some Office
<OPTION VALUE="2"> Warehouse Yard
</SELECT>
答案 0 :(得分:0)
当您使用不兼容的代码时,它仅适用于Internet Explorer
使用:
try {
addrigs.options.add(new Option(featureAttributes[att], att), null); // standards compliant; doesn't work in IE
}
catch(ex) {
addrigs.options.add(new Option(featureAttributes[att], att)) // IE only
}