Javascript 如何将参数名获取为数组?

Javascript 如何将参数名获取为数组?,javascript,arrays,Javascript,Arrays,在我的代码中,我使用的是谷歌地图api。在这里,我对按钮使用onclick方法。如果我动态点击它,它会显示多个文本框。在这里,我为所有文本字段输入值。但当我将参数名传递到servlet页面时,它只接受文本框的第一个值。如何获取所有值 My code var button = document.getElementById('waypoint-input'); button.addEventListener("click", function () { var paren

在我的代码中,我使用的是谷歌地图api。在这里,我对按钮使用onclick方法。如果我动态点击它,它会显示多个文本框。在这里,我为所有文本字段输入值。但当我将参数名传递到servlet页面时,它只接受文本框的第一个值。如何获取所有值

My code

  var button = document.getElementById('waypoint-input');

  button.addEventListener("click", function () {

      var parentNode = document.getElementById('waypoints-list');

      var input = document.createElement('input');
      input.type = 'text';      
      input.placeholder = 'Enter a waypoint location';
      input.id = 'waypoint' + me.waypointIndex;
      input.inputId = me.waypointIndex;
      **input.name = 'waypointlist';**

      input.addEventListener('input', function () {

          if (input.value == "") {

              var waypoint = me.waypts.filter(function (obj) {
                  return obj.key === input.inputId;
              })[0];

              if (waypoint != null && typeof waypoint !== "undefined") {

                  var waypointIndexToRemove = me.waypts.map(function (el) {
                      return el.key;
                  }).indexOf(input.inputId);

                  me.waypts.splice(waypointIndexToRemove, 1);

                  me.route();
              }
          }
      });

      var removeInput = document.createElement('button');
      removeInput.innerHTML = 'Remove';
      removeInput.onclick = function () {
          parentNode.removeChild(input);
          parentNode.removeChild(removeInput);

          var childInputs = parentNode.getElementsByTagName('input');

          if (childInputs.length > 0) {
              for (var i = 0; i < childInputs.length; i++) {
                  childInputs[i].inputId = i;
              }
          }

          if (input.value != "" && input.value != null) {

              var waypointIndexToRemove = me.waypts.map(function (el) {
                  return el.key;
              }).indexOf(input.inputId);

              me.waypts.splice(waypointIndexToRemove, 1);

              for (var i = input.inputId; i < me.waypts.length; i++) {
                  me.waypts[i].key = me.waypts[i].key - 1;
              }

              me.route();
          }

          me.waypointIndex--;
      }

      parentNode.appendChild(input);
      parentNode.appendChild(removeInput);

      var waypointAutocomplete = new google.maps.places.Autocomplete(input, { placeIdOnly: true });

      me.setupPlaceChangedListener(waypointAutocomplete, 'WAYPOINT', input.inputId);

      me.waypointIndex++;

  }, false);
我的代码
var按钮=document.getElementById('waypoint-input');
按钮。addEventListener(“单击”),函数(){
var parentNode=document.getElementById('waypoints-list');
var input=document.createElement('input');
input.type='text';
input.placeholder='输入航路点位置';
input.id='waypoint'+me.waypointIndex;
input.inputId=me.waypointIndex;
**input.name='waypointlist'**
addEventListener('input',function(){
如果(input.value==“”){
var航路点=me.waypts.filter(功能(obj){
返回obj.key==input.inputId;
})[0];
如果(航路点!=null&&typeof航路点!=“未定义”){
var waypointIndexToRemove=me.waypts.map(函数(el){
返回el.key;
}).indexOf(input.inputId);
me.航路点拼接(航路点索引移动,1);
我。路线();
}
}
});
var removeInput=document.createElement('button');
removeInput.innerHTML='Remove';
removeInput.onclick=函数(){
parentNode.removeChild(输入);
parentNode.removeChild(removeInput);
var childInputs=parentNode.getElementsByTagName('input');
如果(childInputs.length>0){
对于(变量i=0;i
我找到了问题的答案。
我的脚本没有更改。我只是在servlet页面中调用参数名。名称是waypointlist。我稍微修改了一下servlet代码。
就是
String[]waypointlist=request.getParameterValues(“waypointlist”);
字符串waypointarray=“”;

for(int i=0;我查看javascript如何将参数序列化到服务器。您可能使用了错误的请求mime类型对其进行编码。是的,感谢您的回复亲爱的john philip。我找到了问题的解决方案。不客气。也许您可以发布一个答案来帮助其他有相同问题的人吗?是的,当然……我将发布:)您可以执行
String waypointarray=waypointlist.join('/')那么你就不需要for循环了。。。使用字符串函数是可能的。是的,谢谢你的回复
        I found the solution to my question.

There is no changes to my script. I simply call the parameter name in servlet page. The name is waypointlist. And I change my servlet code little bit.

That is

    String[] waypointlist=request.getParameterValues("waypointlist");

    String waypointarray="";

                for(int i=0;i<waypointlist.length;i++)
                {
                    waypointarray += waypointlist[i] +"/";
                }