Ruft die ausgewählte Options-ID mit jQuery ab
Ich versuche jQuery zu machen eine ajax-Anforderung, basierend auf einer ausgewählten option.
Gibt es eine einfache Möglichkeit zum abrufen der ausgewählten option id (z.B. "id2") mithilfe von jQuery?
<select id="my_select">
<option value="o1" id="id1">Option1</option>
<option value="o2" id="id2">Option2</option>
</select>
$("#my_select").change(function() {
//do something with the id of the selected option
});
InformationsquelleAutor der Frage ISBL | 2010-05-22
Du musst angemeldet sein, um einen Kommentar abzugeben.
Können Sie es mithilfe der
:ausgewählt
- Selektorwie diese:InformationsquelleAutor der Antwort Nick Craver
dann tun Sie, was Sie wollen mit
selectedIndex
Habe ich reedited meine Antwort ... da selectedIndex ist nicht eine gute variable zu geben, Beispiel...
InformationsquelleAutor der Antwort Mihai Iorga
InformationsquelleAutor der Antwort wild_nothing
Th einfachste Weg, um dieses ist var id = $(this).val(); von innen, so ein event auf ändern.
InformationsquelleAutor der Antwort jk121960