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

  • B4ROK

    B4ROK

    1 EKİM 2008
  • H3Ctic (old channel)

    H3Ctic (old

    23 Mart 2011
  • UCBerkeley

    UCBerkeley

    3 Mayıs 2006