JS Retrieves the index number of selected items in the drop-down list box (SELECTEDEX)

Before starting this theme, first look at an HTML DEMO, a very simple selection list (SELECT):

   One   Three       

Please think about it, if these data (one / two / three) is requested from the background and dynamically add rendering to the DOM system, you can’t determine the index number of each list item, which means There is no ID of these list items. Obviously, we need to get the list item selected by the user and the index number (ID) of the current list item. JS检索下拉列表框中被选项目的索引号(selectedIndex)

SelectedIndex API

JavaScript provides a method of finding a SELECT ID index number, which reflects the first or final selection index component, This depends on the value Multiple, note that the value is -1 indicates that no elements are selected.

The SelectedIndex property sets or returns the index number of the selected option in the drop-down list. If you allow multiple options, you only return the first index number of the selected option.

// Get the indectelem.selected index // Reset index number (newIndex is new) SelectElem

Obtaining an index / reset index
  We can use the API provided by JavaScript to get the current user selection list. The index number of the item. Of course, weYou can also reset (change) the index number.  

One

TWO

Three

Get the index number
      JavaScript:        summarizes 
Give you the search number of the selected item in the JS Retrieval drop-down list box, I hope to help everyone. If you have any questions, please leave a message, the small package will reply to everyone. Thank you very much for your support of Tumi Cloud Website!

If you think this article helps you help you, welcome to reprint, please indicate the source,Thanks!

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment