Javascript 如何从服务器端检索的值设置selecthtml元素的值

Javascript 如何从服务器端检索的值设置selecthtml元素的值,javascript,jquery,html,json,struts,Javascript,Jquery,Html,Json,Struts,我有一个组合框或html的select元素。我想通过从服务器检索的值设置这个html元素的值 从服务器阵列检索的值。我想解析这个数组并设置html元素的值 在服务器端使用struts 1.3。我已经在一个数组中设置了服务器端的值,并以动作形式设置了它的值。现在,在不使用scriptlets的情况下,我希望检索这些值,并使用javscript将该值设置为html元素 示例代码 <table width="100%"> <tr><td>&nbsp;<

我有一个组合框或html的select元素。我想通过从服务器检索的值设置这个html元素的值

从服务器阵列检索的值。我想解析这个数组并设置html元素的值

在服务器端使用struts 1.3。我已经在一个数组中设置了服务器端的值,并以动作形式设置了它的值。现在,在不使用scriptlets的情况下,我希望检索这些值,并使用javscript将该值设置为html元素

示例代码

<table width="100%">
<tr><td>&nbsp;</td></tr>

<tr>
     <td width="40%" align="right"><bean:message key="com.console.pack1"/>:</td>
        <td>
                <select name="n1">
                        <option value="0">A</option>
                        <option value="1">B</option>
                        <option value="3">C</option>
                </select>

        </td>
      </td>
</tr>
<tr id="line_second">
   <td width="40%" align="right"><bean:message key="com.console.pack2"/>:</td>
     <td>
        <select name="n2">
                        <option value="0">A</option>  // set the values of option from the array retrieved from struts action form
                        <option value="1">B</option>
                        <option value="3">C</option>
        </select>
    </td>
   </td>
</tr>
如何在html元素中设置此值

是否有任何可行的解决办法。任何想法


**请记住:*来自服务器的html元素的值是动态的。

Idk如何获取数组我相信您知道

//set the select element to a variable

var selectEl = document.querySelector('select');

var data = [1,2,3,4,5]
for(var d of data){
 selectEl.appendChild(new Option(d, d)); //the new Option() takes two arguments 1: innerText, 2: value
}
//set the select element to a variable

var selectEl = document.querySelector('select');

var data = [1,2,3,4,5]
for(var d of data){
 selectEl.appendChild(new Option(d, d)); //the new Option() takes two arguments 1: innerText, 2: value
}