Home  >  Article  >  Web Front-end  >  Questions about addEventListener_html/css_WEB-ITnose

Questions about addEventListener_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:17:201488browse

Helping others debug a piece of code. After debugging for a while, I found that there are many problems and my head is spinning. Please help me.

<!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>


Reply to the discussion (solution)

8bb454ffdba61e6afd0af258930d20d3
93f0f5c25f18dab9d176bd4f6de5d30e
9c0c15d7f3bc220895adf78d998e90ad
b2386ffb911b14667cb8f0f91ea547a7Untitled Document6e916e0f7d1e588d4f442bf645aedb2f
4ec11beb6c39d0703d1751d203c17053
var p= "";
function init(){
var a=document.links[0];
if(document.body.attachEvent){
a.attachEvent("onmousedown",function() {change(1,a)});
a.attachEvent("onmouseup",function(){change(0,a)});
}else if(document.body.addEventListener){
a.addEventListener("mousedown",function(){change(1,a)},false);
a.addEventListener("mouseup",function(){change(0,a)},false);
}
}
function change(isChange,src){
if(isChange){
p=window.setTimeout(function(){src.style.color="yellow"; },2000);
}else{
window.clearTimeout(p);
}
return false;
}
window.onload=init;
3fa3f474cbb4b6d948eebecb1be5dde4
9c3bca370b5104690d9ef395f2c5f8d1

6c04bd5ca3fcae76e30b72ad730ca86d
8aa2918506a11e8a886e85949f1eb079Press me for two seconds to change color5db79b134e9f6b82c0b36e0489ee08ed
36cc49f0c466276486e50c850b7e4956
73a6ac4ed44ffec12cee46588e518a5e
Try this

Statement:
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