0

我有这个代码来验证这一点。

<script type="text/javascript"> <!-- alert("Testing"); --> </script>

此代码现在在表单页面上创建一个弹出框。一切都按预期工作!现在我遇到的问题是引用下拉框。我认为下面的代码应该可以解决问题,但没有。

var element; var i=EG;
element=document.getElementById("client_country"); element.selectedIndex = i;

但我似乎无法让它工作。我认为这是由于使用了框架,任何人都可以指出我哪里出错了?

4

1 回答 1

0
var i = 'EG'; // string inside quotes
var element = document.getElementById("client_country");
element.value = i; // set the selected option

// selectedIndex retrieves the value
var selected_value = element.options[element.selectedIndex].value;

这假设您的 HTML 类似于...

<select id="client_country">
    <option value="AG">value a</option>
    <option value="CG">value c</option>
    <option value="EG">value e</option>
</select>

JSFiddle上的工作演示。

于 2013-01-17T06:55:50.847 回答