簡體   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--;
}));

上面的代碼是根據下拉選擇選項添加一個文本框。 它最多可以添加 3 個文本框。 如何將此文本框值傳遞給 spring MVC 控制器。

您似乎正在使用 JQuery 來構建 UI。 假設您在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM