js禁止

很多时候需要用到js禁止相关的代码:

function prohibit() {
  // 禁止右键
  $(document).ready(function() {
    $(document).bind("contextmenu", function(e) {
      return false;
    }); 
  
    // 禁止a
    $("a").each(function() {
      $(this).css("cursor", "default"); // 修改鼠标样式
      $(this).removeAttr('href'); //移除href 属性
      $(this).click(function(event) {
        event.preventDefault(); // 如果<a>定义了 target="_blank“ 需要这句来阻止打开新页面
      });

    });
  });
}
prohibit();

 

posted @ 2017-10-29 11:53  叫我小龙哥  阅读(189)  评论(0编辑  收藏  举报