2

我编写了以下代码来检索数组 abc 中“recipientList”的值,但它不起作用。每当我使用

alert(abc[i]);

它返回“未定义”。我需要使用这个 abc[i] 的值作为 'options[]' 索引

document.getElementById("recipients").options[i].selected

我究竟做错了什么?

var abc;

    <logic:greaterThan value="0" property="ConfigId" name="ConfigForm">
    <%

    ArrayList<RecipientDTO> recipientList= (ArrayList<RecipientDTO>) request.getAttribute("recipientTypesList");
    if (recipientList != null && recipientList.size() > 0) 
    {
            for (int i=0; i < recipientList.size(); i++) 
             {
                RecipientDTO recipientType = (RecipientDTO) recipientList.get(i);%>
                abc = [<%=recipientType.getRecipientType().toString()%>];
    <%  } %> 

    var i;      
    for(i=0;i<abc.length;i++) {

        document.getElementById("recipients").options[i].selected = true; 

    }       

<% }
    %>
    </logic:greaterThan>

我也用过

var abc = new Array();
abc[i] = "<%=recipientType.getRecipientType().toString()%>";

代替

var abc;
abc = [<%=recipientType.getRecipientType().toString()%>];

但没用:(

4

1 回答 1

1

尝试用var abcvar abc=new Array()替换

abc = [<%=recipientType.getRecipientType().toString()%>];

abc[<%=i%>] = '<%=recipientType.getRecipientType().toString()%>';
于 2012-09-02T16:30:59.390 回答