2012-06-26 28 views
0

如何測試是否有未來,因爲這不希望工作jQuery的nextAll()函數,檢查是否有下一個

它計算3種元素的所有時間由於某種原因?

$("body "+content).on("keypress","form.fcheckoutform :input.aantal",function(e) { 
     if (e.keyCode === 9) { 

      var nextItem = $(this).nextAll(); 

      if (!nextItem.length) { 
       $(content+ '.aantal:eq(0)').focus(); 
       return false; 
      } 
      $(this).nextAll().focus(); 
     } 
    }); 

編輯: 解決

$("body "+content).on("keypress","form.fcheckoutform :input.aantal",function(e) { 
     e.preventDefault(); 
     if (e.keyCode === 9) { 
      var nextItem = $(this).parents('.item-checkout').next().children('form').children('div.fr').find('.aantal'); 
      if (!nextItem.length) { 
       $(content+ ' .aantal:first').focus(); 
      }else{ 
       nextItem.focus(); 
      } 
     } 
    }); 

感謝,理查德

+0

的.next()應該已經足夠了,它會返回0或1個元素是基於在sele之後是否有元素元素。 –

+0

下一個diddn't爲我工作,它只是選擇下一個元素,但沒有關閉相同的類型 – Richard

+0

添加一個選擇器.nextAll()來選擇只匹配當前類型的元素。 –

回答

0

試試這個:

$("body "+content).on("keypress","form.fcheckoutform :input.aantal",function(e) { 
    if (e.keyCode === 9) { 

     var nextItem = $(this).nextUntil(':input.aantal').next(); 

     if (!nextItem.length) { 
      $(content+ '.aantal:eq(0)').focus(); 
      return false; 
     } 
     $(this).nextUntil(':input.aantal').next().focus(); 
    } 
}); 
+0

不,它不起作用 – Richard

+0

輸入是否以任何方式嵌套? (如內部divs或標籤) –

+0

是的內部div的,你可以檢查www.woonbel.nl - klik左uppercorner – Richard

相關問題