SORU
16 Mart 2010, Salı


jQuery: click fonksiyonu çocuk hariç.

JQuery kafamda bir yere oturtmaya çalışıyorum ".()" fonksiyonu, ve bir sorunla karşılaşmak. Ana div "" ama eğer bir kullanıcı bir alt öğe üzerinde tıklama, komut dosyası denir. tıklanabilir olmasını istiyorum

$(this).not(children()).click(function(){
   $(".example").fadeOut("fast");
});

html:

<div class="example">
   <div>
      <p>This content is not affected by clicks.</p>
   </div>
</div>

CEVAP
20 HAZİRAN 2011, PAZARTESİ


Ve aynı sorun encoutered vardı: biçimlendirme aşağıdaki kullanıyorum

<ul class="nav">
    <li><a href="abc.html">abc</a></li>
    <li><a href="def.html">def</a></li>
</ul>

Burada şu mantığı kullandım:

$(".nav > li").click(function(e){
    if(e.target != this) return; // only continue if the target itself has been clicked
    // this section only processes if the .nav > li itself is clicked.
    alert("you clicked .nav > li, but not it's children");
});

Tam soru açısından, bu aşağıdaki gibi çalıştığını görüyorum

$(".example").click(function(e){
   if(e.target != this) return; // only continue if the target itself has been clicked
   $(".example").fadeOut("fast");
});

ya da tam tersi tabii:

$(".example").click(function(e){
   if(e.target == this){ // only if the target itself has been clicked
       $(".example").fadeOut("fast");
   }
});

Bu yardımcı olur umarım.

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Exalto_Gamer

    Exalto_Gamer

    15 EKİM 2014
  • Kamikazeepanda

    Kamikazeepan

    5 ŞUBAT 2006
  • Lupe Fiasco

    Lupe Fiasco

    23 ŞUBAT 2006