0

我正在调用一个返回变量的 javascript

options = '<option value="' + dateVal + '">' + dateText + '</option>' + '<option value="' + dateVal + '">' + dateText + '</option>';

我的select元素也有一个 id="select-value" 并且在 javascript 中我正在编写 document.getElementById("select-value").value=options;但它没有采用任何值也没有抛出任何错误我也尝试过 document.getElementById("select-value").innerHTML=options;但仍然没有运气。

PFB 我的 html 代码select

<select name="select-name"  id="select-value" ></select>
 <script type="text/javascript">
   formatSelectedDate();
 </script>
4

1 回答 1

0

我建议使用 appendChild 而不是 innerHTML。

var s = document.getElementById("select-id");
var op1 = document.createElement("option");
op1.setAttribute("value",dateval);
s.appendChild(op1);
...

编辑:在循环中看起来更好;)

于 2013-09-05T09:46:32.650 回答