【问题标题】:Javascript auto tab not working on iPad or iPhoneJavascript 自动选项卡在 iPad 或 iPhone 上不起作用
【发布时间】:2012-04-18 02:28:21
【问题描述】:

我有这段 html 代码:

    <form name="postcode" method="post" onsubmit="return OnSubmitForm();">
<input class="postcode" maxlength="1" size="1" name="c" onKeyup="autotab(this, document.postcode.o)" /> 
<input class="postcode" maxlength="1" size="1" name="o" onKeyup="autotab(this, document.postcode.d)" /> 
<input class="postcode" maxlength="1" size="1" name="d" onKeyup="autotab(this, document.postcode.e)" /> 
<input class="postcode" maxlength="1" size="1" name="e" /> <br />
    </form>

使用这个javascript:

<script>
/*
Auto tabbing script- By JavaScriptKit.com
http://www.javascriptkit.com
This credit MUST stay intact for use
*/
function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}
</script><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script src="js/scripts.js" type="text/javascript"></script>

<script type="text/javascript">
function OnSubmitForm()
{
  if(document.postcode.operation[0].checked == true)
  {
    document.postcode.action ="plans.php";
  }
  else
  if(document.postcode.operation[1].checked == true)
  {
    document.postcode.action ="plans_gas.php";
  }
  else
  if(document.postcode.operation[2].checked == true)
  {
    document.postcode.action ="plans_duel.php";
  }

  return true;
}
</script>

只要您在其中一个文本框中输入一个字符,它就会自动跳到下一个文本框。

这在 pc 或 mac 以及 safari 以及所有其他浏览器上都可以正常工作。但是在 iPad 或 iPhone 上(使用 safari)查看网页时,自动选项卡功能不起作用。

关于如何使自动标签在这些移动设备上工作的任何想法?

【问题讨论】:

  • 您已连续两次发布此问题。

标签: javascript iphone html ios ipad


【解决方案1】:

在我上次使用移动 Safari 时,我需要将事件“onKeyUp”更改为“onKeyPress”,您尝试过吗?

【讨论】:

    【解决方案2】:

    根据设计,据我所知,移动 Safari 中的输入字段禁用焦点。

    【讨论】:

    • 所以看起来我可能需要看看 focus() 的替代方法来做同样的事情......
    猜你喜欢
    • 1970-01-01
    • 2012-05-03
    • 2013-02-23
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    相关资源
    最近更新 更多