简体   繁体   English

Javascript-输入按钮在Android中不起作用,其他所有功能

[英]Javascript - Input button won't work in Android, everything else works

I have a form. 我有一个表格。 In this form there is an input area. 在这种形式下,有一个输入区域。 When the user selects the input they are taken to one of three places depending on which device they are using. 用户选择输入时,将根据他们使用的设备将其带到三个位置之一。 android - google play store, iphone - itunes store, desktop - itunes web browser. android-Google Play商店,iphone-iTunes商店,桌​​面-iTunes Web浏览器。 I am able to retrieve the iphone and desktop states, however Android doesn't seem to work on the form tag with an action attribute. 我能够检索iphone和桌面状态,但是Android似乎无法在带action属性的form标签上使用。 The links work fine. 链接工作正常。 Not sure what the issue is. 不知道是什么问题。 Summary -- when I click the input button, nothing happens, no pop ups, nothing on my android. 总结-当我单击输入按钮时,什么也没有发生,没有弹出窗口,在我的android上什么也没有。 Also when I place the url of http://www.google.com into the action attribute of form it works correctly. 另外,当我将http://www.google.com的网址放入表单的action属性中时,它也可以正常工作。 Something is happening in between. 两者之间发生了一些事情。

<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>

Try .. 试试..

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM