简体   繁体   English

java - 如何将动态添加的文本框传递给spring MVC控制器java

[英]How to pass dynamically added textbox to spring MVC controller java

    $("#addButton").click(function () {
    if(counter > 3){
            alert("Only 3 textboxes allowed");
            return false;
    }
    var selectfield = $('#selectcolumnlist option:selected').val();
    var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv');   
    newTextBoxDiv.after().html('<input type="text" name="textbox_' + selectfield + '" class="form-control" id="textbox_'+selectfield+'" placeholder="' + selectfield + '" value="" style="width: 400px;"/><input type="button" value="Remove Field" class="remove_this" id="removeid" accessKey="'+selectfield+'"/>');
    newTextBoxDiv.appendTo("#TextBoxesGroup");
    $('#selectcolumnlist option:selected').remove();
    counter++;
});

$("#TextBoxesGroup").on('click', '#removeid', (function() {
    var a = $(this).attr('accessKey');
    alert(a);
    $(this).parent('div').remove();
    $('#selectcolumnlist').append(new Option(a,a));
    counter--;
}));

Above code is adding a textbox based on the dropdown select option.上面的代码是根据下拉选择选项添加一个文本框。 It can add a maximum of 3 textboxes.它最多可以添加 3 个文本框。 How do I pass this textbox value to spring MVC controller.如何将此文本框值传递给 spring MVC 控制器。

It appears that you are using JQuery to build the UI.您似乎正在使用 JQuery 来构建 UI。 Assuming that you have a Spring MVC endpoint exposed at POST http://localhost:8080/api/boxes you can use jQuery.ajax() method:假设您在POST http://localhost:8080/api/boxes处公开了一个 Spring MVC 端点,您可以使用jQuery.ajax()方法:

$.ajax({
  method: "POST",
  url: "http://localhost:8080/api/boxes",
  data: { textbox: "value" }
})
.done(function(msg) {
  alert("Saved: " + msg);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将具有数据的文本框值传递给spring MVC控制器? - How to pass textbox value which has the data to spring MVC controller? 如何传递文本框值以及对spring mvc控制器的作用是什么? - How to pass textbox values and what was the action to spring mvc controller? 如何将javascript变量传递给Spring mvc控制器 - how to pass javascript variable to Spring mvc controller 如何在Spring MVC中将LIST从一个控制器传递到另一个控制器 - How to pass LIST from one controller to another controller in spring mvc Java:Spring:如何将参数动态传递给构造函数? - Java: Spring : How to pass params to the constructor dynamically? 如何将单击的单选按钮的值传递给Spring MVC控制器? - How to pass value of radio button which is clicked to Spring MVC controller? 如何在Spring MVC中使用jQuery Ajax serialize()将文件传递给控制器 - how to pass file to controller using jquery ajax serialize() in spring mvc 如何通过onclick将对象参数传递给控制器​​Spring MVC - How to pass a object parameter to the controller Spring mvc by an onclick 如何从JSP中的循环将Spring MVC模型传递给控制器 - How to pass Spring MVC model to controller from a loop in JSP 如何将嵌套的列表元素传递给spring mvc中的控制器 - How to pass nested list element to the controller in spring mvc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM