How to get the text value of a selected item from a DataList using jQuery
问题 How do I get the text value of the options in a DataList? I need to make use of the value of an id , But I also need the value of the selectedIndex, which is the name. <input type="text" name="names[]" id="names" list="neym"/> <datalist id="neym"> <option value="example"></option> <option value="example2"></option> <option value="example3"></option> </datalist> How do I do that in jQuery? 回答1: Loop through them and use text() and val() as others have pointed out: $('#neym option').each