最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I want to disabled onClick event for image inside div onClick function? - Stack Overflow

programmeradmin1浏览0评论

I want to disable click event for image using image id eg. for id12 i want to disabled click event . i tried using unbind but it seems it only works if event is binded using j query?

I want to disable click event for image using image id eg. for id12 i want to disabled click event . i tried using unbind but it seems it only works if event is binded using j query?

Share Improve this question edited May 24, 2013 at 13:44 KhAn SaAb asked May 24, 2013 at 13:16 KhAn SaAbKhAn SaAb 5,3766 gold badges34 silver badges54 bronze badges 3
  • You can try this, onclick="return false;" – Satpal Commented May 24, 2013 at 13:19
  • unbind should work for any events; additionally try off for newer Query versions – feeela Commented May 24, 2013 at 13:19
  • are i have div on click of Div inside click function i want to disable image click event – KhAn SaAb Commented May 24, 2013 at 13:21
Add a ment  | 

6 Answers 6

Reset to default 7
$("#id12").on('click',function(e){
  e.preventDefault();
});
$("#id12").on('click',function(){
  return false;
});
$("#id12").click(function () { return false; });

$("#id12").on('click',function(e){ e.preventDefault(); });

    $("#id12").on('click',function(e){
       e.preventDefault();
    });

Below is pure javascript code. Try this :

document.getElementById('id12').setAttribute("onclick", null);
发布评论

评论列表(0)

  1. 暂无评论