disable mouse event on 1st and re-enable the same on 3rd click - javascript

回眸只為那壹抹淺笑 提交于 2019-12-08 11:48:15

问题


I have a div which changes colors on multiple onclick events.

var linkClick = 1; 
  function update_link(obj){ 
  if (linkClick == 1){obj.style.border = 'solid 1px red'};
  if (linkClick == 2){obj.style.border = 'solid 1px blue'};
  if (linkClick == 3){obj.style.border = 'solid 1px green'};
  if (linkClick >3 ) {obj.style.border = 'solid 1px #555555'; linkClick=0};
  linkClick++; 
}

and in html: onclick="update_link(this);"

I need onmouseenter and onmouseleave to be disabled when I click the 1st time, and to be re-enabled again when I click the 3rd time.

I've tried to put this.onmouseleave='null' in onclick but I don't know how to re-enable it with another click or event.

Does somebody knows how to achieve this?

来源:https://stackoverflow.com/questions/18044757/disable-mouse-event-on-1st-and-re-enable-the-same-on-3rd-click-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!