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

  • B3ASTTY™

    B3ASTTY™

    27 Mayıs 2013
  • dope2111

    dope2111

    29 HAZİRAN 2009
  • HowtoDrawAndPaint

    HowtoDrawAnd

    24 EKİM 2010