Setting hidden datalist option values

前端 未结 5 695
旧巷少年郎
旧巷少年郎 2020-12-06 09:55

In the snippet below, I have two methods to choose an item: input with datalist and traditional select with options.

The select element keeps the option values hidde

5条回答
  •  时光取名叫无心
    2020-12-06 10:38

    Do not know this will help you, just made a try

      
      
            
           
            
            
           
            
      
    
    
    
    
     $( document ).ready(function() {              
             var x =  document.getElementById("options");
               for (i = 0; i < x.length; i++)
                alert(x.options[i].value);     
    
    
                $("#opt").click(function(){
                     $("#opt").val("");});                   
                 });
    
         function onInput() {
                var val = document.getElementById("opt").value;
                var opts = document.getElementById('options').childNodes;
                 for (var i = 0; i < opts.length; i++) {
                        if (opts[i].value === val) {                
                        document.getElementById("opt").value = opts[i].value + "   "+ opts[i].innerHTML;
                        break;
                      }
                    }
                  }
    

提交回复
热议问题