[英]How to get dynamic textbox value from div with dynamic id's
我有一個應用程序,其中有一個記錄列表。 我必須動態綁定到div。 我必須為每個記錄添加一個文本框。
現在,對於每個選定的記錄,我還必須獲取用戶在文本框中輸入的值。
我想獲取選定人員的電子郵件地址(無論用戶在文本框中鍵入該選定記錄的任何內容)
<div class="row">
<input type="checkbox"> <label>Bob</label> Email: <input type="textbox"/>
</div>
<div class="row">
<input type="checkbox"> <label>Bob</label> Email: <input type="textbox"/>
</div>
<div class="row">
<input type="checkbox"> <label>Bob</label> Email: <input type="textbox"/>
</div>
<button onclick="saveSelectedEmail()">Submit</button>
<script>
function saveSelectedEmail(){
}
</script>
我想獲取選定人員的電子郵件地址(無論用戶在文本框中鍵入該選定記錄的任何內容)
您可以使用Javascript或Jquery
Java腳本
<!DOCTYPE html>
<html>
<body>
Name: <input type="text" id="myText" value="Mickey">
<p>Click the button to change the value of the text field.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
console.log(document.getElementById("myText").value)
document.getElementById("myText").value = "Johnny Bravo";
}
</script>
</body>
</html>
您需要為每個字段或div輸入一個動態ID。
HTML代碼
<table id="userData" class="table table-striped table-bordered" width="100%">
<thead>
<tr>
<th>Select</th>
<th>Loan Id</th>
<th>User</th>
<th>Lender</th>
</tr>
</thead>
<tbody>
{% for emi in emis %}
<tr>
<td><input type="checkbox" class="checkMe" name="checkBox" id="{{emi.userId._id.toString()}}"></td>
<td>{{ emi._id.toString().slice(-6) }}</td>
<td><a href="/admins/users/{{ emi.userId._id.toString() }}">{{ emi.userId.name }}</a></td>
<td><a href="/admins/users/{{ emi.lenderId._id.toString() }}">{{ emi.lenderId.name }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
Javascript功能
$('.checkMe').on('click', function() {
var id = $(this).attr('id');
if (arr.includes(id)) {
let index = arr.indexOf(id);
arr.splice(index, 1);
} else {
arr.push(id);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.