סלקטור selected
תיאור: תואם לכל האלמנטים מסומנים.
jQuery(':selected')
הוספה בגרסה: 1.0
סלקטור :selected
עובד עבור אלמנטים
<option>.
הוא לא עובד עבור תיבות סימון וכפתורי רדיו;
עבורם תשתמשו ב-
:checked.
דוגמאות
בלחיצה על אלמנט של הרשימה מופיע ערך שלו באלמנט DIV שלמטה.קוד מלא:
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ $("select").change(function () { var str = ""; $("select option:selected").each(function () { str += $(this).text() + " "; }); $("div").text(str); }) .trigger('change'); }); </script> <style> div { color:red; } </style> </head> <body> <select name="garden" multiple="multiple"> <option>Flowers</option> <option selected="selected">Shrubs</option> <option>Trees</option> <option selected="selected">Bushes</option> <option>Grass</option> <option>Dirt</option> </select> <div></div> </body> </html>
האם מידע זה היה מועיל?

