zoukankan      html  css  js  c++  java
  • jquery中on绑定click事件在苹果手机失效问题解决(巨坑啊)

    描述:用一个div写一个按钮,并给这个按钮添加一个点击事件,在安卓机器上一切正常,但是在苹果机型上会出现点击事件失效。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .redButton{
                width: 50px;
                height: 50px;
                background: red;
                text-align: center;
                line-height: 50px;
            }
        </style>
    </head>
    <body>
    <div class="button">
        <div class="redButton">
            按钮
        </div>
    </div>
    
    <script src="jquery-3.0.0.min.js"></script>
    <script>
        $(document).on("click",".redButton",function(){
            alert('点击了按钮');
        });
    </script>
    
    </body>
    </html>

    解决苹果机点击失效代码:
    为什么会出现这个问题:苹果机对于点击的对象,要拥有cursor:pointer这个样式的设置,也就是说,鼠标放上去,能够出现“手”型的图标才被认作可以使用点击事件,然后就加一行css咯~

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .redButton{
                width: 50px;
                height: 50px;
                background: red;
                text-align: center;
                line-height: 50px;
                cursor:pointer;     //光标呈现为指示链接的指针
            }
        </style>
    </head>
    <body>
    <div class="button">
        <div class="redButton">
            按钮
        </div>
    </div>
    
    <script src="jquery-3.0.0.min.js"></script>
    <script>
        $(document).on("click",".redButton",function(){
            alert('点击了按钮');
        });
    </script>
    
    </body>
    </html>

    链接:https://www.jianshu.com/p/8456191f8ee9

  • 相关阅读:
    [BZOJ 2820]YY的GCD
    [POI 2007]ZAP-Queries
    [USACO 04OPEN]MooFest
    [HAOI 2011]Problem b
    [COGS 2258][HZOI 2015]复仇的序幕曲
    [UOJ 41]【清华集训2014】矩阵变换
    [POJ 3487]The Stable Marriage Problem
    [POJ 3252]Round Numbers
    [COGS 1799][国家集训队2012]tree(伍一鸣)
    [SDOI 2011]计算器
  • 原文地址:https://www.cnblogs.com/lxwphp/p/10281133.html
Copyright © 2011-2022 走看看