帮别人调试一段代码,调试了一会,发现有很多问题,头都大了,还请大家帮忙
<!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>
Copier après la connexion
回复讨论(解决方案)
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>
按我两秒变色 这样试试