javascript - 移动端安卓按钮具有获取焦点和失去焦点,ios却没有反应

查看:100
本文介绍了javascript - 移动端安卓按钮具有获取焦点和失去焦点,ios却没有反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

  <style>
    button,input{
      width: 100px;
      height: 100px;
      margin-top: 100px;
    }
  </style>
</head>
<body>


<input type="button" value="input按钮">
<button>button按钮</button>

<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
 
<script>
    $(function(){
        $("input").on("touchstart", function(){
            $(this).val("input focus");
        }).on("touchend", function(){
            $(this).val("input blur");
        });


        $("button").on("touchstart", function(){
            $(this).text("button focus");
        }).on("touchend", function(){
            $(this).text("button blur");
        });
 });

</script> 
</body>
</html>


项目中遇到使用安卓手机点击按钮可以获得焦点和失去焦点。IOS系统的却获取不到,这是为什么呢

解决方案

你试试touch的。
三种在规范中列出并获得跨移动设备广泛实现的基本触摸事件:

 1. touchstart:手指放在一个DOM元素上。
 2. touchmove:手指拖曳一个DOM元素。
 3. touchend:手指从一个DOM元素上移开。

这篇关于javascript - 移动端安卓按钮具有获取焦点和失去焦点,ios却没有反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆