亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

打字時自動改變焦點

打字時自動改變焦點

素胚勾勒不出你 2023-07-14 14:57:30
我需要在第一個字段中輸入 4 個字符后將焦點自動轉移到第二個字段。<input type="text" id="input1"><input type="text" id="input2">$("#input1").change(function() {    if ($(this).val().length == 4) {        $("#input2").focus();    }});但這不起作用。我缺少什么?我也嘗試過document.getElementById("input2").focus();但它也不起作用。
查看完整描述

1 回答

?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

你只需要使用keyup事件而不是change其他邏輯將按原樣工作


$(function(){

  $("#input1").on('keyup', function() {

    if ($(this).val().length == 4) {

        $("#input2").focus();

    }

 });

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>

<input type="text" id="input1">

<input type="text" id="input2">


查看完整回答
反對 回復 2023-07-14
  • 1 回答
  • 0 關注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號