javascript - 如何设置输入焦点?
<p><p>我正在开发一个 WebApp,并想用 html 创建一种登录屏幕。为此,我有四个输入字段,它们专注于输入数字后的下一个字段。</p>
<p>在 osX safari 中,这可以正常工作。与我 iPhone 上的 iOS 不同。哟呼。 </p>
<p>移动 safari 的问题是我不知道如何以编程方式自动“跳转”到下一个输入字段(以编程方式设置焦点)。用户可以通过按钮来完成(工作正常),但有没有办法自动完成?</p>
<p><strong>查看我的代码:</strong></p>
<p></p><div class="snippet"data-lang="js"data-hide="false"data-console="true"data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$('.text').on('input', function() {
$(this).next('input').focus()
});</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>.text {
margin: 5%;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="text" />
<input type="text" class="text" />
<input type="text" class="text" />
<input type="text" class="text" /></code></pre>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>因为我很确定有人也会遇到这个问题,所以我决定回答我自己的问题。 </p>
<p><strong>所以我使用这行代码部分解决了这个问题:</strong></p>
<pre><code>myWebView.keyboardDisplayRequiresUserAction = false
</code></pre>
<p>我在阅读 UIWebView 的苹果文档时找到了解决方案。</p>
<p>请看 <a href="https://developer.apple.com/documentation/uikit/uiwebview/1617967-keyboarddisplayrequiresuseractio" rel="noreferrer noopener nofollow">reference</a> .</p></p>
<p style="font-size: 20px;">关于javascript - 如何设置输入焦点?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/51466857/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/51466857/
</a>
</p>
页:
[1]