Get selected value in datalist using jQuery

后端 未结 9 1848
终归单人心
终归单人心 2020-12-06 11:46

Very simple and straight forward. I pre-populated a HTML datalist with values, on the form when I want select a value and insert it into SQLite database. This is my example

相关标签:
9条回答
  • 2020-12-06 12:12
    <input list="Model" id="ModelList" placeholder="Select Model"> 
    <datalist id="Model">
    <option value="A">
    <option value="B">
    <option value="C">
    <option value="D">
    </datalist>
    <script>
    var dataset= document.getElementById("ModelList").value;
    alert(dataset);</script>
    
    0 讨论(0)
  • 2020-12-06 12:13

    I would use '.on()':

    HTML

    <input type="text" name="display" id="display" value="" list="list-display" />
    <datalist id="list-display">
     <option>Name</option>
     <option>Id</option>
    </datalist>
    

    Javascript

    $("#display").on('input',function(e){
     alert($(this).val());
    });
    
    0 讨论(0)
  • 2020-12-06 12:13

    try .val() instead :

    var relationshipTemp = $('#TypeList option:selected').val();
    
    0 讨论(0)
提交回复
热议问题