JQuery: Disable click event

前端 未结 5 1989
梦如初夏
梦如初夏 2021-01-15 09:56

I want to disable all click events on my page but some of events are still getting called, suppose I have html as below

5条回答
  •  被撕碎了的回忆
    2021-01-15 10:24

    There is an attribute you should use to make all things disabled.

    var nodes = document.getElementById("parent").getElementsByTagName('*');
    for(var i = 0; i < nodes.length; i++) {
         nodes[i].disabled = true;
    }
    

    Unfortunately disable is not valid with anchor tags.

    There you should use :

    var nodes = document.getElementById("parent").getElementsByTagName('a');
    for(var i = 0; i < nodes.length; i++) {
      nodes[i].onclick = function(e){
        e.preventDefault();
        // YOUR CODES HERE
      }
    }
    

    try to combine these two methods according to your needs

提交回复
热议问题