2016-12-07 2 views
1

Ich benutze bootstrap combobox Plugin.Bootstrap Combobox und Auswahl Wert nach der Eingabe

Wenn Sie aus der Combo NewYork auswählen funktioniert es gut, aber wenn Sie New eingeben und dann versuchen, New York aus dem Menü auszuwählen, funktioniert es nicht.

Das Beispiel kann here gefunden werden.

+0

versuchen diesen https://jsfiddle.net/poosanth/neceegbv/6/ das 'change' Ereignis zu ändern, um' click' Veranstaltung – prasanth

Antwort

0

Versuchen Sie, diese:

Demo fiddle Änderung der change Ereignis click Ereignis

$('.combobox').on('click', function(){ 

Alternate

Tragen Sie die, wenn die Bedingung für option value

if(option.val()){ 
    alert('Value is ' + option.val()); 
    } 

Demo fiddle

0

Es wird adaequat:

$('.combobox').combobox(); 

var val = '', newVal = null; 

$('.combobox').on('select', function(){ 

    newVal = $(this).val(); 

    if (newVal !== val) { 
     val = newVal; 
     alert('Value is ' + val); 
    } 

}); 
0

$('#combobox').combobox(); 
 
$('#combobox').on('change', function(){ 
 
\t if($(this).val()){ 
 
     console.log("You selected: "+$(this).val()); 
 
     alert('Value is ' + $(this).val()); 
 
    } 
 
})
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://rawgit.com/danielfarrell/bootstrap-combobox/master/css/bootstrap-combobox.css" rel="stylesheet"/> 
 
<script src="https://rawgit.com/danielfarrell/bootstrap-combobox/master/js/bootstrap-combobox.js"></script> 
 
<div> 
 
    <select class="combobox" id="combobox"> 
 
     <option></option> 
 
     <option value="PA">Pennsylvania</option> 
 
     <option value="CT">Connecticut</option> 
 
     <option value="NY">New York</option> 
 
     <option value="MD">Maryland</option> 
 
     <option value="VA">Virginia</option> 
 
    </select> 
 
</div>

auch in Geige überprüfen: https://jsfiddle.net/neceegbv/8/

Analysieren Sie diesen Code mit class und id Sie sehen den Unterschied.

-1

Ihr js Fiddle Snippet ist richtig, aber es gibt ein Problem auf Alarm Funktion. So entfernen Sie die Alarmfunktion und setzen Sie Konsole Methode, um den ausgewählten Wert wie unten Snippet zu finden.

Hoffnung hilft Ihnen.

$('.combobox').combobox(); 
 
$('.combobox').on('change', function(){ 
 
    var option = $(this).find('option:selected'); 
 
\t if(option.length){ 
 
    console.log(option.val()); 
 
    } 
 
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://rawgit.com/danielfarrell/bootstrap-combobox/master/css/bootstrap-combobox.css" rel="stylesheet"/> 
 
<script src="https://rawgit.com/danielfarrell/bootstrap-combobox/master/js/bootstrap-combobox.js"></script> 
 
<br><br> 
 
<div class="container"> 
 
\t <div class="row"> 
 
\t \t <div class="col-sm-4"> 
 
\t  <select class="combobox form-control" id="combobox" data-placeholder="Enter City Name"> 
 
\t  \t <option></option> 
 
\t  <option value="PA">Pennsylvania</option> 
 
\t  <option value="CT">Connecticut</option> 
 
\t  <option value="NY">New York</option> 
 
\t  <option value="MD">Maryland</option> 
 
\t  <option value="VA">Virginia</option> 
 
\t  </select> 
 
\t </div> 
 
\t </div> 
 
</div>

Verwandte Themen