Auswahl von next() Eingang

Lesezeit: 1 Minute

Ich habe folgendes html:

<div>
    <input type="text" maxlength="2" class="day-spin-month"></input>
    <span>/</span>
    <input type="text" maxlength="2" class="day-spin-day"></input>
    <span>/</span>
    <input type="text" maxlength="4" class="day-spin-year"></input>
</div>

Ich versuche, den Fokus auf die nächste Eingabe zu ändern. Ich habe es auf die folgenden 2 Arten funktioniert.

$('.day-spin-month').on('keyup', function () {
    if (this.value.length >= 2) {
       $(this).next().next().focus();
    }
});
$('.day-spin-day').on('keyup', function () {
    if (this.value.length >= 2) {
       $(this).next().next().focus();
    }
});

Geige: http://jsfiddle.net/dan_vitch/JbQaN/1/

$('.day-spin-month').on('keyup', function () {
    if (this.value.length >= 2) {
       var test=$(this).next()
       var test2=  $(test).next('input');
       test2.focus();
     }
});
$('.day-spin-day').on('keyup', function () {
    if (this.value.length >= 2) {
        var test=$(this).next()
        var test2=  $(test).next('input');
        test2.focus();
    }
});

Geige: http://jsfiddle.net/dan_vitch/JbQaN/2/

aber so geht das nicht:

$('.day-spin-month').on('keyup', function () {
    if (this.value.length >= 2) {
       $(this).next('input').focus();
    }
});
$('.day-spin-day').on('keyup', function () {
    if (this.value.length >= 2) {
       $(this).next('input').focus();
    }
});

Geige: http://jsfiddle.net/dan_vitch/rJwyE/2/

Ich möchte den Weg verwenden, der nicht funktioniert. Ich bin mir nicht sicher, ob mein Selektor so falsch ist oder wie ich next verstehe ()

  • stackoverflow.com/questions/290535/…

    – Morten Anderson

    12. Dezember 2011 um 23:11 Uhr

.nächste() betrachtet nur das nächste Geschwisterelement im DOM. IE.

$('.day-spin-month').next('input');

Wird mit nichts übereinstimmen, da das nächste Geschwister eine Spanne und keine Eingabe ist.

nextAll() sieht sich alle nächsten Geschwister an, also willst du:

$(this).nextAll('input').first().focus();

1037900cookie-checkAuswahl von next() Eingang

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy