javascript中的touchstart事件,求写法
来源:互联网 发布:中日技术贸易 数据 编辑:程序博客网 时间:2024/05/29 08:50
转自:http://zhidao.baidu.com/link?url=qKoz6JGcPAr6eIXB_O-wExzcVPXnVmlKzNy0kr1TIS9bwHO0yuRjPCTLHAped-wA9WYUAwmcHZBrhY31xRTSaFfRYxDNtN0MzoD_UTuPXvW
2014-09-19 09:48jlgtczdtyt | 分类:JavaScript | 浏览815次
通过touchstart这个事件,在手机端web页面中,有下面一个div:<div id="test"> <ul> <li>中华人民共和国</li> <li>北京你好啊</li> <li>世界第一等</li> </ul></div>希望手指触摸到(没点)某一个<li>时,将这一行的背景色变成红色,移开后恢复,这个js要如何处理啊?求教,谢谢。
提问者采纳
热心网友
function load(){ document.addEventListener('touchstart',fn, false); document.addEventListener('touchmove',fn, false); document.addEventListener('touchend',fn, false); function fn(event){ var event = event || window.event; var ele=获取你要的元素; switch(event.type){ case "touchstart": 接触时的操作 break; case "touchend": 连续滑动时的操作 break; case "touchmove": event.preventDefault();//取消事件的默认动作 离开时的操作 break; } }}window.addEventListener('load',load, false);
追问
谢谢,不过还有个问题,就是这一句 var ele=获取你要的元素; 这一段不太会写,是获取id为test的div中的li的元素。 请教!^_^
回答
var ele=document.getElementById('test');var ul=ele.childNodes.item(0);var li=ul.childNodes;for(var i=0;i<li.length;i++){alert("Item "+i+": "+li.item(i).innerHTML);}
- 提问者评价
谢谢!
提问者采纳
热心网友
function load(){ document.addEventListener('touchstart',fn, false); document.addEventListener('touchmove',fn, false); document.addEventListener('touchend',fn, false); function fn(event){ var event = event || window.event; var ele=获取你要的元素; switch(event.type){ case "touchstart": 接触时的操作 break; case "touchend": 连续滑动时的操作 break; case "touchmove": event.preventDefault();//取消事件的默认动作 离开时的操作 break; } }}window.addEventListener('load',load, false);
追问
谢谢,不过还有个问题,就是这一句 var ele=获取你要的元素; 这一段不太会写,是获取id为test的div中的li的元素。 请教!^_^
回答
var ele=document.getElementById('test');var ul=ele.childNodes.item(0);var li=ul.childNodes;for(var i=0;i<li.length;i++){alert("Item "+i+": "+li.item(i).innerHTML);}
- 提问者评价
谢谢!
0 0
- javascript中的touchstart事件,求写法
- html 移动互联网终端的javascript touch事件,touchstart, touchend, touchmove
- html 移动互联网终端的javascript touch事件,touchstart, touchend, touchmove
- html 移动互联网终端的javascript touch事件,touchstart, touchend, touchmove
- 触摸三事件touchstart,touchend,touchmove
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- 【HTML5】触摸事件(touchstart、touchmove和touchend)
- 触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- h5触摸事件:touchstart、touchmove和touchend
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- HTML5触摸事件(touchstart、touchmove和touchend)
- PHP之路之Html篇 I
- R语言 分类数据折线图绘制
- Codeforces Round #300 解题报告(ABCDEF)
- Android SDK镜像的介绍使用
- windows Gvim 中文乱码问题解决
- javascript中的touchstart事件,求写法
- Unity3d实现的十字路口的模拟(一)
- Android类似Dialog弹出变暗
- #job 23
- java.lang.OutOfMemoryError: PermGen
- Step into Scala - 10 - 映射和元组
- Git学习笔记(一)
- web前端优化
- java初学者从这里开始