我正在尝试将CLOSED的值重新写入TESTING。请注意,选择框是动态填充的。我的代码如下,但它没有产生预期的结果。
<html>
<head>
<script type="text/javascript">
window.onload = function() { loadit() }
function loadit(){
var x = new Array()
x[0] = ""
x[1] = "ACTIVE"
x[2] = "ON HOLD"
x[3] = "CLOSED"
for (i=0; i<x.length; i++)
{
document.getElementById('d1').options[i]=new Option(x[i], i)
}
}
function changeit() {
var el = document.getElementById("d1");
for(var i=0; i < el.options.length; i++)
{
if(el.options[i].value == "CLOSED")
{
el.options[i].value = "TESTING";
el.options[i].innerText = "TESTING";
}
}
}
</script>
</head>
<body>
<select name="d1" id="d1" style="width: 200px;"></select>
<p><a href="javascript:changeit()">change</a></p>
</body>
</html>