自动填写复制粘贴的电话号码字段

时间:2017-06-21 06:11:17

标签: javascript jquery html html5

我对webdev有点新鲜,而且作为一个整体的html,还在学习。我有一个包含3个字段的基本电话号码表单,并且一直在尝试制作它,以便您可以将号码复制到字段中。是否会检查前一个字段是否已填满,然后在下一个框中填入下一部分的数字? 感谢您提供的任何帮助 (这里是html)

<html>
<head>

<title>Phone Input Test</title>
<script type= javascript>
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
  var keyCode = (isNN) ? e.which : e.keyCode;
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }

function containsElement(arr, ele) {
  var found = false, index = 0;
  while(!found && index < arr.length)
    if(arr[index] == ele)
      found = true;
    else
      enter code here
    index++;
  return found;
}

function getIndex(input) {
  var index = -1, i = 0, found = false;
  while (i < input.form.length && index == -1)
    if (input.form[i] == input)
      index = i;
    else 
      i++;
  return index;
}
return true;
}
</script>

</head>
<body bgcolor=#ffffff>
<form action="phonetest.html" method="post">
<input type="text" name="dest_ac" size=3 onKeyUp="return autoTab(this, 3, event);" maxlength=3>
<input type="text" name="dest_niu" size=3 onKeyUp="return autoTab(this, 3, event);" maxlength=3>
<input type="text" name="dest_st" size=4 maxlength=4>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

&#13;
&#13;
public class ListWrapper<E> {

    private List<E> list;

    public ListWrapper() {
        list = new ArrayList<>();
    }

    public ListWrapper(List<E> list) {
        this.list = list;
    }

    @Valid
    public List<E> getList() {
        return list;
    }

    public void setList(List<E> list) {
        this.list = list;
    }

    public boolean add(E e) {
        return list.add(e);
    }

    public void clear() {
        list.clear();
    }

}
&#13;
    $(function () {

            var $inputs = $(".def-txt-input");
            var intRegex = /^\d+$/;

            $inputs.on("input.fromManual", function () {
                if (!intRegex.test($(this).val())) {
                    $(this).val("");
                }
            });


            $inputs.on("paste", function () {
                $inputs.attr("maxlength", 15);
                var $this = $(this);
                var originalValue = $this.val();
                
    
                $this.val("");
    
                $this.one("input.fromPaste", function () {

                    var values = $(this).val().match(/.{1,1}/g);
                    $("#txtBox1").val("");
                    $inputs.attr("maxlength", 5);
                    for (i = 0; i < values.length; i++) {
                        if ($("#txtBox1").val().length < 5) {
                            this.value = this.value.toString() + values[i];
                        }
                        else if ($("#txtBox2").val().length < 5) {
                            $("#txtBox2").val( $("#txtBox2").val().toString() + values[i]);
                        }
                        else if ($("#txtBox3").val().length < 5){
                            $("#txtBox3").val($("#txtBox3").val().toString() + values[i]);
                        }
                    }

                });

               
            });
        });
&#13;
&#13;
&#13;

相关问题