简体   繁体   English

检测到跨度时未选择下一个输入元素

[英]Next input element is not selected when span is detected

I have a set of input elements within 2 span block. 我在2个span块内有一组输入元素。 I need to automatically select next input element by using onKeup(). 我需要通过使用onKeup()自动选择下一个输入元素。 This works fine until span tag is found. 在找到span标记之前,它可以正常工作。 After that it is not detecting. 之后,它没有检测到。

In the following code next input element is detected until 3rd input box after that it is not detected. 在下面的代码中,将检测到下一个输入元素,直到第三个输入框都没有被检测到为止。

Can any one help with this? 有人能帮忙吗?

http://jsfiddle.net/et3escuh/8/ http://jsfiddle.net/et3escuh/8/

<span>
<input id="opnamenummer6" class="form-control" type="text" name="opnamenummer6" value="" maxlength="1">
<input id="opnamenummer7" class="form-control" type="text" name="opnamenummer7" value="" maxlength="1">
<input id="opnamenummer8" class="form-control" type="text" name="opnamenummer8" value="" maxlength="1">
</span>


<script type="text/javascript">
$('input[class*="form-control"]').keyup(function(event) {
    var $this = $(this);
    var currentLength = $this.val().length;
    var maximumLength = $this.attr('maxlength');
    // if we've filled up this input, go to the next if only numerics are entered.
    if ( (currentLength == maximumLength) && ((event.which >= 48 && event.which <= 57) || (event.which >= 96 && event.which<= 105))) {
        $this.next().select();
    }
    //go to previous input if Backspace or Delete buton is pressed
    if(event.which == 8 || event.which == 46) {
        $(this).val('');
        $(this).prev('input').select();
    }
});

</script>

Don't use next() , use eq() and add or subtract to the index 不要使用next() ,请使用eq()并在索引中添加或减去

$('input[class*="form-control"]').keyup(function(event) {
    var $this = $(this);
    var currentLength = $this.val().length;
    var maximumLength = $this.attr('maxlength');

    if ( (currentLength == maximumLength) && (!isNaN(this.value))) {
        $('input').eq($(this).index('input') + 1).select();
    }

    if(event.which == 8 || event.which == 46) {
        $(this).val('');
        $('input').eq($(this).index('input') - 1).select();
    }
});

FIDDLE 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM