我正在尝试使用javascript填充HTML下拉框,并且在Google Chrome中可以正常运行,但是当我在IE11上尝试不起作用
下面是我的代码:
document.getElementById("startTime").value = myVariable;
任何人都知道如何使它在IE11中工作吗?
答案 0 :(得分:0)
我尝试使用下面的代码对IE 11进行测试。
<!doctype html>
<head>
<script>
function SelectElement(id, valueToSelect)
{
var element = document.getElementById(id);
element.value = valueToSelect;
alert("string length= " + valueToSelect.length);
}
</script>
</head>
<body>
<input type="button" onclick="SelectElement('startTime', '08:30 am')" value="set value"/>
<select id="startTime" name="startTime">
<option value="07:30 am">07:30 am</option>
<option value="08:30 am">08:30 am</option>
<option value="09:30 am">09:30 am</option>
<option value="10:30 am">10:30 am</option>
<option value="11:30 am">11:30 am</option>
</select>
</body>
</html>
输出:
您可以看到我的代码工作正常,字符串长度也为8个字符。
您可以尝试使用此代码示例进行测试,并检查其是否正常工作。
如果问题仍然存在,请尝试提供完整的示例代码,并尝试发布输出。我们将尝试进行检查,并尝试为您提供进一步的建议以解决该问题。