我有一個從后端加載的動態表單資料。如果有靜態表單,我可以通過 document.getElementById("xxx") 獲取值。但是,如果有未知 id 的動態表單,我該如何獲取值?我想有這些格式提交就可以了
"answers" :[
{
"questionId" : 1002,
"response" : "Yes"
},{
"questionId" : 1001,
"response" : "No"
}
]
這是stackblitz鏈接
uj5u.com熱心網友回復:
將您的表單欄位放在
form標簽內(包括提交按鈕)。給表格上課,例如
custom-form在選擇器上添加提交偵聽
.custom-form器。$('.custom-form').on('submit', function formSubmitHandler(event) { // add logic here });在提交處理程式中,通過執行以下操作獲取輸入欄位:
const formInputs = $(this).find("input"); //this will retrieve all the input tags inside the form.您現在可以遍歷它們并執行您想要的操作。
uj5u.com熱心網友回復:
當你在表單上回圈時,你可以從后端獲取的資料中生成類名或 id,或者你可以構造一個新的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/491718.html
標籤:javascript jQuery 形式 for循环 提交
上一篇:修改字典以洗掉專案
