Ich möchte dem Benutzer antworten, der ein Element in einem Auswahlelement auswählt. Doch diese jQuery:Welches Ereignis wird ausgelöst, wenn Element in der HTML-Auswahl/Dropdown-Liste ausgewählt ist?
$('#platypusDropDown').select(function() {
alert('You selected something');
});
... tut nichts. Es zeigt keine Warnung an, obwohl jsFiddle es als gültige jQuery ansieht.
Das Click-Ereignis funktioniert, aber es ist zu schnell - es wird beim Klicken auf das Element select ausgelöst, bevor eine Auswahl getroffen wird.
Natürlich, ich möchte wirklich wie etwas tun:
$('#platypusDropDown').select(function() {
var selection = $('platypusDropDown').val;
$.getJSON('platypus.json', selection, data() {
// . . .
});
});
Die HTML:
<select id="platypusDropDown">
<option value="duckbill">duckbill</option>
<option value="duckbillPlatypus">duckbillPlatypus</option>
<option value="Platypus">Platypus</option>
<option value="Platypi">Platypi</option>
</select>