第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

怎么在JS中設置賬號框按回車鍵光標直接移動到密碼輸入框

怎么在JS中設置賬號框按回車鍵光標直接移動到密碼輸入框

qq_笑_17 2019-04-26 17:15:40
獲取元素,然后判斷鍵盤是否按下的是回車,然后呢?該怎么辦?下邊代碼根本沒有用<p>賬號:<input type="text" autofocus/></p> <p>密碼:<input type="password" ></p> <p><button>登錄</button></p> <script>     var plist=document.querySelectorAll('p');     plist[0].onkeydown=function(){         if(event.keyCode==13){             this.childNodes[1].removeAttribute('autofocus');             this.nextSibling.nextSibling.childNodes[1].setAttribute('autofocus',true);         }     } </script>
查看完整描述

2 回答

?
滄海一幻覺

TA貢獻1824條經(jīng)驗 獲得超5個贊

 <form>
    <p>賬號:<input type="text" autofocus /></p>
    <p>密碼:<input type="password"></p>
    <p><button>登錄</button></p>
</form>
<script>
    var plist = document.querySelectorAll('p');
    plist[0].onkeydown = function (e) {
        e = e || window.event; 

        if (e.keyCode == 13) {
            plist[1].querySelector('input').focus();
            return false;;//阻止表單提交
        }
    }
</script>


查看完整回答
反對 回復 2019-05-13
?
汪汪一只貓

TA貢獻1898條經(jīng)驗 獲得超8個贊

一般不會這樣操作,按tab鍵好了,如果你執(zhí)意要用回車,首先你得判斷如果賬號和密碼有一個為空button不可被點擊,因為回車會默認點擊button和
input[type=submit]的按鈕

查看完整回答
反對 回復 2019-05-13
  • 2 回答
  • 0 關注
  • 718 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號