2017-10-16 58 views
0

只要我的頁面加載,我的重點是用戶輸入第一個數字到otp。當我這樣做的jQuery,默認情況下,數字鍵盤不visible.later我手動如果我的重點,我得到的數字鍵盤。如何解決這個問題?jquery聚焦到數字輸入不會觸發手機的數字鍵盤

這裏是我的代碼:

setTimeout(function(){ 
       Ember.$('.digit0').focus(); 
      }, 100); 

我的html:

{{#each cardDigitField as |field index| }} 
       <input type="number" tabindex="{{count}}" min="0" max="9" maxlength="1" value='' 
        pattern="[0-9]*" inputmode="numeric" 
        onKeyUp={{action "numberEntered" index }} 
        onKeyPress={{action "numberInit" }} 
        onPaste={{action "numberPaste" }} class="digit{{index}}" > 
        {{#if requiredHyphen}} 
         {{add-hyphen index 4 cardDigitField.length}} 
        {{/if}} 
      {{/each}} 
+0

您是否嘗試使用['input'](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input)的'autofocus'屬性? – ykaragol

回答

1

一般setTimeout和Ember的runloop不玩在一起很好。如果你在你的組件中使用afterRender鉤子,那麼你的jQuery有更好的成功嗎?

相關問題