내 데이터베이스의 내용 목록을 응용 프로그램에 표시합니다. 데이터베이스에서 레코드를 가져 와서 프런트 엔드의 for-each 루프를 반복하고 내용을 표시합니다. 항목 중 하나를 클릭하려고하면 목록의 첫 번째 항목 만 표시됩니다. 아래는 제 코드입니다. 이 문제를 어떻게 극복 할 수 있습니까?Javascript를 사용하여 선택한 목록 항목을 얻는 방법?
function userselection()
{
var selecteduser1=document.getElementById("lbl_user").innerHTML;
document.writeln(selecteduser1);
}
<div style="border: 2px solid activeborder;width:300px;height: 400px;border-radius: 5px;">
<ul id="userlist" style="text-align: left;">
<c:forEach items="${list_onlineusers}" var="userslist">
<li id="li_user" style="list-style-image: url(images/online.png);cursor: pointer;height: 25px;margin-left: 0;margin-right: 10%;margin-top: 0.5em;margin-bottom: 7%;" value="${userslist}">
<label onmousedown="userselection()" id="lbl_user" style="font-family:Trebuchet MS,Times,serif;color: black;font-size: 16px;cursor: pointer;">
${userslist}
</label>
</li>
</c:forEach>
</ul>
</div>
대신 모든 항목을 선택 하시겠습니까? –
@Sn. 아니요 하나의 항목을 선택하고 해당 데이터로 제 기능을 계속하고 싶습니다 – user3458482
"lbl_user $ {index}"와 같은 ID를 사용하고 있습니다 –