【问题标题】:Getting onClick to work on iPad Safari在 iPad Safari 上使用 onClick
【发布时间】:2014-03-19 00:12:54
【问题描述】:

我刚刚继承了一个网站,大约 15 年没有在网站上工作过,对触摸屏编程并不熟悉。

我有以下 onClick 提交代码,该代码适用于我测试过的所有浏览器(包括 PC 上的 Safari 桌面)以及在 iPad 上使用 Google 搜索,但在访问网站时尝试按下“提交”按钮时通过 iPad Safari 它不会触发。我已经搜索了 JQuery 解决方案,但没有跟上 JQuery 的速度。任何帮助表示赞赏。

函数提交条目() { 密码 = document.password1.password2.value.toLowerCase() 用户名 = document.password1.username2.value.toLowerCase() 密码 = 1 用户代码 = 1 for(i = 0; 我
<center>
<form action="" name="password1">
<strong>User * * : </strong>
<input type="text" name="username2" size="15">
<br>
<strong>Password: </strong>
<input type="password" name="password2" size="15">
<br><br>
<input type="button" value="Submit"onClick="submitentry(); return true">
</form>

【问题讨论】:

    标签: ipad


    【解决方案1】:

    事实证明,在 jQuery 中分配了点击处理程序的任何非锚元素都必须具有 onClick 属性(可以为空,如下所示):

    onClick=""

    元素css需要有如下声明:

    光标:指针

    通过:http://www.mitch-solutions.com/blog/17-ipad-jquery-live-click-events-not-working

    【讨论】:

      【解决方案2】:

      我不确定,但可能是因为触控设备没有指针。

      试试 .live():

      $(document).ready(function(){
          $("#submitButton").live("click", function(){
              // do something
          }
      });
      

      或者,试试这个插件: https://github.com/aanand/jquery.tappable.js


      我建议您尽量避免编写不显眼的代码,例如 onclick、onmousedown 等内联事件处理程序,因为不同的浏览器工作方式不同。尤其是在触控设备中。

      【讨论】:

        【解决方案3】:

        感谢您的建议。作为 jQuery 的新手,我需要一段时间才能跟上进度。到目前为止,以下是我要做的工作,但在使用 Safari 访问该站点时,iPad 上的触摸屏仍然存在问题。 但它确实有效,奇怪的是,当我在 iPad 上使用 Google 访问该网站时。奇怪,我觉得!

        我的 HTML 输入语句是:

        <input type="button" value="Submit" id="click"/>
        

        jQuery:

        $('#click') .click(function(){
          submitentry();
          });
        

        我在想,如果我使用 .click 以外的其他东西,它可能会起作用。只需要弄清楚是什么。我们拭目以待……

        【讨论】:

          猜你喜欢
          • 2012-01-27
          • 2012-03-06
          • 2011-09-07
          • 1970-01-01
          • 1970-01-01
          • 2012-08-04
          • 2011-10-03
          • 2016-11-01
          • 2011-03-01
          相关资源
          最近更新 更多