我为 < slect
创建了动态 ID > 。这是代码-
<% int i = 0; %>
<c:forEach var="pro" items="${proofingListsWithRoles.allList}" varStatus="status">
<tr>
<td id="jobId">${pro.jobId}</td>
<td>
<select id="selectRole<%=i %>" onchange="javascript:selectRole('selectRole<%=i %>')">
<c:forEach items="${pro.roles}" var="rol" varStatus="status">
<option value="${rol.id}"> <c:out value="${rol.name}"/></option>
</c:forEach>
</select>
</td>
</tr>
<% i++; %>
</c:forEach>
现在我的目标是从dropdown.The following
中找出所选 Angular 色的哪个id警报()print selectRoel0, selectRole1, selectRole2,... . Notice selectRole0, selectRole1 etc are id of <select>
.自 <slect>
在 forEach 循环中有多个 <select>
.这里在 function(selectId){} seelctId
里面用于获取selectRole0、selectRole1 ....等的值。所以使用<select>
的id内部函数 selectRole(selectId){} 如何获取从 dropdown
中选择的 Angular 色.
function selectRole(selectId){
alert(selectId);
}
最佳答案
在函数内使用以下内容。
$('#' + selectId).val();
关于javascript - 从变量中获取动态 ID 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26886796/