小编典典

如何在JavaScript函数中访问JSP数组

jsp

如何在单个jsp页面中使用javascript函数访问jsp数组?

String[] abc[]={"saab","volvo","bmw","Benz","Porsche","Jaguar"};
abc[0]="saab";

阅读 351

收藏
2020-06-10

共1个答案

小编典典

<%  
String[] abc={'saab',' volvo',"bmw","Benz","Porsche","Jaguar"};  
%>

<script language="JavaScript">

var jsArr = new Array();  
<%  
for (int i=0; i < abc.length; i++) {  
%>  
jsArr[<%= i %>] = '<%=abc[i] %>';   //Here is the latest update check it sravan .Put single quotes.
<%}%> 
</script>

  function myFunction()
  {
    var select = document.getElementById("dropDownId");

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

      var option = document.createElement("option");
      // set the text that displays for the option
       option.innerHTML = status[i];
     // add the option to your select dropdown
       select.appendChild(option);

   }
2020-06-10