Get the value of the input element with the same name

Our page in the foreground defines many input elements with the same name. In order to get the corresponding value, one is that we can do this in js:

var djs= new Array();
$("input[name='dj']").each(function(){
 djs.push($(this).val());
 });

We put the value of the input with the same name into the array by the above method. When we use ajax to pass values ​​to the background, we need to pass strings

The following method needs to be used to convert the array to a string.

The JavaScript array join() method joins all elements of an array as a string.

var dj=djs.join(",");

This results in a string.

The background is directly divided to get List<String> dj = Arrays.asList(dj.split(",")); a linked list.

The other gets directly in the background:

Use request.getParamters("dj"); to get an array of strings. You can use it directly.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325154775&siteId=291194637