关于addEventListener问题_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:17:20
Original
1446 people have browsed it

帮别人调试一段代码,调试了一会,发现有很多问题,头都大了,还请大家帮忙

<!DOCTYPE html><html><head><SCRIPT TYPE="text/javascript" SRC="jquery.js"></SCRIPT></head><body><a href="" title="">Long press</a><p>长时间点击2秒后我会变颜色</p><script type=text/javascript>   function down(){    var timeout = window.setTimeout(function() {$("p").css("color","yellow");},1000);});function up(){    $("p").css("color","black");});$("a").addEventListener("mousedown",down,false); $("a").addEventListener("mouseup",up,false); </script> </body></html>
Copy after login


回复讨论(解决方案)

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



无标题文档
<script> <br /> var p=""; <br /> function init(){ <br /> var a=document.links[0]; <br /> if(document.body.attachEvent){ <br /> a.attachEvent("onmousedown",function(){change(1,a)}); <br /> a.attachEvent("onmouseup",function(){change(0,a)}); <br /> }else if(document.body.addEventListener){ <br /> a.addEventListener("mousedown",function(){change(1,a)},false); <br /> a.addEventListener("mouseup",function(){change(0,a)},false); <br /> } <br /> } <br /> function change(isChange,src){ <br /> if(isChange){ <br /> p=window.setTimeout(function(){src.style.color="yellow";},2000); <br /> }else{ <br /> window.clearTimeout(p); <br /> } <br /> return false; <br /> } <br /> window.onload=init; <br /> </script>



按我两秒变色


这样试试
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!