SORU
18 NİSAN 2012, ÇARŞAMBA


Nasıl bu seçenek seçili ise, onay için?

$('#mySelectBox option').each(function() {
    if ($(this).isChecked())
       alert('this option is selected');
     else
       alert('this is not');
});

Görünüşe göre, isChecked çalışmıyor. YANİ benim soru bu yapmak için doğru yolu nedir? Teşekkürler.

CEVAP
18 NİSAN 2012, ÇARŞAMBA


GÜNCELLEME

Bu seçenek seçili için daha doğrudan bir WordPress kullanmak bir yöntem:

var selected_option = $('#mySelectBox option:selected');

Sen ne arıyorsun sorusu .is(':selected') cevap:

$('#mySelectBox option').each(function() {
    if($(this).is(':selected')) ...

Sigara jQuery (tartışmasız en iyi uygulama) bunu yapmak için bir yol olabilir:

$('#mySelectBox option').each(function() {
    if(this.selected) ...

Eğer sadece seçili değeri için arıyorsanız, ancak, deneyin:

$('#mySelectBox').val()

Eğer arıyorsanız seçilen değeri text yapın:

$('#mySelectBox option').filter(':selected').text();

Kontrol: http://api.jquery.com/selected-selector/

Bir dahaki sefere soruları çoğaltmak için bak:

Get current selected option ya Set selected option ya How to get $(this) selected option in jQuery? ya option[selected=true] doesn't work

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Dopelives

    Dopelives

    30 Temmuz 2009
  • kylediablo

    kylediablo

    8 Ocak 2007
  • The Fashion Sight

    The Fashion

    22 AĞUSTOS 2011