【问题标题】:Javascript - Input button won't work in Android, everything else worksJavascript - 输入按钮在 Android 中不起作用,其他一切正常
【发布时间】:2016-12-16 01:31:16
【问题描述】:

我有一个表格。在这种形式中,有一个输入区域。当用户选择输入时,他们将被带到三个位置之一,具体取决于他们使用的设备。 android - google play 商店,iphone - iTunes 商店,桌面 - iTunes 网络浏览器。我能够检索 iphone 和桌面状态,但是 Android 似乎不适用于具有操作属性的表单标记。链接工作正常。不确定是什么问题。摘要——当我点击输入按钮时,什么也没有发生,没有弹出窗口,我的 android 上什么也没有。此外,当我将 http://www.google.com 的 url 放入表单的 action 属性中时,它可以正常工作。中间发生了一些事情。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name='viewport' content='initial-scale=1'>
</head>
<body>
<div class='main'>

<br/>
<br/>
<br/>
<form id="store-link"  >
    <input type='submit'  value='Download'/>        
</form>
<br/>
<br/>
<br/>
</div>
<div class='footer'>
<p>footer</p>

</div>
</body>
<script>

 var a = document.getElementById('store-link'); 
 if (navigator.userAgent.match(/Android/i)) {
 a.action = 'http://www.google.com';
 }
 if ((navigator.userAgent.match(/iPhone/i)) ||    (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))){
 a.action = 'itms://itunes.apple.com/us/app/peanuts-storygif-christmas/id1181016912?mt=8';
 }
else {
a.action = 'https://itunes.apple.com/us/app/peanuts-storygif-christmas/id1181016912?mt=8';
 }

</script>
 </html>

【问题讨论】:

标签: javascript html


【解决方案1】:

试试..

<form id="store-link"  >
    <input type='submit'  value='Download' onclick="action()" />        
</form>
    <script type="text/javascript">
  function action() {
var a = document.getElementById('store-link'); 
 if (navigator.userAgent.match(/Android/i)) {
 a.setAttribute('action','http://www.google.com');
 }
 if ((navigator.userAgent.match(/iPhone/i)) ||    (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))){
 a.setAttribute('action,'itms://itunes.apple.com/us/app/peanuts-storygif-christmas/id1181016912?mt=8');
 }
else {
a.setAttribute('action','https://itunes.apple.com/us/app/peanuts-storygif-christmas/id1181016912?mt=8');
 }
  }
</script>

【讨论】:

  • 我收到控制台错误 - 未捕获的 TypeError: action is not a function at HTMLInputElement.onclick
  • 你可以使用jquery
  • 这不是一个选项
  • 如上使用javascript's setAttribute()
  • 我只是通过更改函数的名称摆脱了控制台错误,但我仍然得到相同的结果,当我单击输入按钮时没有任何反应。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-18
  • 2019-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多