本文由我司收集整编,推荐下载,如有疑问,请与我司联系
如何使用Javascript获取选定的列表项?
如何使用Javascript获取选定的列表项?[英]How to get a selected list item using Javascript? I display a list of contents from my database in my application. I fetch the records from the database and iterate through the for-each loop in the front end and it displays the contents. When I try to click any of the items it only shows the first item in the list. Below is my code. How can I overcome this issue?
 我在我的应用程序中显示了我的数据库中的内容列表。我从数据库中获取记录并迭代前端的for-each循环并显示内容。当我尝试单击任何项目时,它只显示列表中的第一项。以下是我的代码。我怎样才能克服这个问题?
 function userselection() var ElementById(“lbl_user”).innerHTML;
document.writeln(selecteduser1); div  ul id=“userlist”  c:forEach items=“${list_onlineusers}” var=“userslist”  li id=“li_user” value=“${userslist}”  label onmousedown=“userselection()” id=“lbl_user”  ${userslist} /label  /li  /c:forEach  /ul  /div  The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).The id attribute is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to manipulate the element with the specific id.
如何下载javascript
 id属性指定HTML元素的唯一ID(该值必须在HTML文档中唯一).id属性最常用于指向样式表中的样式,并通过JavaScript(通过HTML DOM)进行操作具有特定id的元素。
  You’re using the same id for all the items in the list. You have to change the c:forEach loop little to add the loop count to the id. so, that each item will have an unique id. Please change your code like below
 您对列表中的所有项目使用相同的ID。您必须更改循环,以将循环计数添加到id。因此,每个项目都有一个唯一的ID。请更改您的代码,如下所示

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。