var studentList = document.getElementById('StudentList');
var selectedLabel = studentList.options[studentList.selectedIndex].getAttribute('label');
編集:
html:
<input type="text" name="Search" size="45px" placeholder=" Search student records." list="StudentList">
<datalist id="StudentList">
<option value="Jake" data-id="145">
</datalist>
js:
var search = document.getElementsByName('Search')[0];
var datalist = document.getElementById('StudentList')[0];
search.addEventListener('change', function(){
var id;
for(var i = 0; i < datalist.options.length; i++){
if(datalist.options[i].value === this.value)
id = datalist.options[i].getAttribute('data-id');
}
// Use id here to search
});