优艾设计网

移动端安卓按钮具有获取焦点和失去焦点,ios却没有反应 财富值63?

优艾设计网 https://www.uibq.com 2023-04-25 11:08 出处:网络 作者:PS自学
<!DOCTYPE html> <html lang=\"en\"> <head> <meta charset=\"UTF-8\"> <title>Document</title> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.

<!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优艾设计网_PS论坛"></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系统的却获取不到,这是为什么呢


男神皇坐看云海把昨日还给我前世 优艾设计网_Photoshop百科 2022-09-20 11:31

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


恆曐的恆鈊 2022-09-20 11:48

优艾设计网_设计百科

jquery已经废弃了bind方法,建议使用on来代替bind,用off来代替unbind。其次,因为你做做了一个会导致浏览器一直弹窗的操作,所以ios的禁止掉了。你input 和button 绑定了获取焦点和失去焦点的两个事件,而且都是弹窗。当你先获取焦点的时候,触发弹出了一个框,弹框的操作会导致元素失去焦点,所以又会触发失去焦点的事件。alert弹窗关闭后,浏览器会归还焦点给之前的元素,所以又会触发获得焦点的事件,如此就会一直弹窗。你可以尝试把你的代码做如下修改:先是建议将所有的bind替换为on,其次将alert替换成比如页面插入一个div并给个id,然后改变这个div中间的文字来看效果


0

精彩评论

暂无评论...
验证码 换一张
取 消