touch 事件用法(只能使用二级dom绑定,例如(addEventlinstener绑定),使用ontouch...是不管用的
来源:互联网 发布:淘宝扣48分还能购物吗 编辑:程序博客网 时间:2024/05/23 16:28
touch 事件 只会 在手机端 有用,常用语手机端。
具体用法如下所示:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale="> <title>Title</title></head><body><input type="button" value="jquery测试 touch事件"><button>原生js测试</button><script src="../node_modules/jquery/dist/jquery.js"></script><script> //触摸开始 调用 $(document).on('touchstart','input',function () { console.log('touch start'); }); //触摸过程中 调用 $(document).on('touchmove','input',function () { console.log('touch move'); }); //触摸结束 调用 $(document).on('touchend','input',function () { console.log('touch end'); }) /* 这种方法是不管用的。 touch一类的方法必须用 二级 dom 绑定, 例如: addeventlinstener var btn = document.getElementsByTagName('button')[0]; btn.ontouchstart = function () { console.log('js start'); } btn.ontouchmove = function () { console.log('js move'); } btn.ontouchend = function () { console.log('js end'); }*/ //原生js 中的 touch 事件 var btn = document.getElementsByTagName('button')[0]; //触摸开始 调用 btn.addEventListener('touchstart',function () { console.log('js start'); }) //触摸过程中调用 btn.addEventListener('touchmove',function () { console.log('js move'); }) //触摸结束调用 btn.addEventListener('touchend',function () { console.log('js end'); })</script></body></html>
阅读全文
1 0
- touch 事件用法(只能使用二级dom绑定,例如(addEventlinstener绑定),使用ontouch...是不管用的
- 怎么使用事件的绑定
- 问题:往mCustomScrollbar绑定的DIV append元素不管用
- Jquery,1.7+后的版本使用.on()绑定事件,动态绑定事件,绑定未来事件
- JQuery事件绑定 on() 的绑定测试与使用禁忌
- javascript 的onclick和click 在 ie 和mozilla中的使用 ;jquery 的dom事件绑定
- 使用jquery当页面打开时,将修改样式的点击事件绑定到Dom
- 使用jQuery卸载绑定的事件
- js:怎么使用事件的绑定
- 怎么使用Js事件的绑定
- AngularJS事件绑定的使用详解
- 新dom 事件绑定
- DOM—事件绑定
- DOM事件绑定
- DOM绑定事件处理器
- Data binding的使用(二)-----事件的绑定监听
- Treeview 的基本使用(动态绑定及一些事件)
- 使用事件委托降低重复的事件绑定,从而降低dom操作的对性能的消耗
- 一笔画问题
- Leetcode Construct Binary Tree from Inorder and Postorder Traversal
- 【题解】洛谷P1057 NOIP普及组2008 传球游戏(ball)
- Java微信公众平台开发之发送模板消息
- Unity写代码日常(六)
- touch 事件用法(只能使用二级dom绑定,例如(addEventlinstener绑定),使用ontouch...是不管用的
- ViewGroup.LayoutParams
- Navicat Premium 快捷键
- java写入文件的几种方法分享
- mybatis缓存与数据实时更新
- 用vs调试unity3d (unity3d+vs)
- 如何用equals判断两个对象是否相等
- Android WebView 基本用法
- 思维导图之经典案例