簡體   English   中英

如何從動態選擇的創建checkboes列表中獲取檢查值?

[英]how to get checked value from a list of dynamically selected created checkboes?

我在這里動態填充了我的復選框(使用百里香)。 當我的頁面被加載時,我有一個帶有動態分配值的復選框列表。

 <ul class="list"> <li th:each="model: ${model}"> <input type="checkbox" class="cbCheck" th:field="*{model}" th:value="${model}" /> <label th:text="${model}"></label> </li> </ul>

當用戶按下“提交”按鈕時,我需要選中復選框的值。 任何解決方案?

我試着給他們一個共同的名字。 並像這樣訪問值:

var list = $("input[name='inputCheck']:checked").map(function () {
    return this.value;
}).get();

alert(list);


}

但是警報總是空的。 想要一些解決方案嗎?

使用的整個代碼:

<body>
<h2> LIST OF RULES ACTIVE</h2>
<div id="RuleList">
    <ul class="list">
       <li th:each="model : ${model}">
         <input type="checkbox" name="inputCheck" th:id="${model}" th:field="*{model}" th:value="${model}" />
         <label th:text="${model}"></label>
      </li>
   </ul>
   <button type="button" onclick="sendResponse()" id="DeActivate">DeActivate</button>
</div>
<br/>
<br/>
<script>

function sendResponse()
{
/*var array = [];
if(document.getElementsByName("inputCheck").checked)
    {
    array.push(document.getElementsByName("inputCheck").value);
    alert(array);
    }

}*/



var list = $("input[name='inputCheck']:checked").map(function () {
    return this.value;
}).get();

alert(list);


}

</script>

</body>

程序流程未進入復選框選中條件。

嘗試這個:

var list = document.querySelectorAll('.cbCheck');
for (i=0; i<list .length; i++){
    alert(check[i].value)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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