Disable click on a div

后端 未结 4 1397
名媛妹妹
名媛妹妹 2021-01-19 13:07

I want to disable click on a certain

so that when you select the text on it, the text doesn\'t select.

I tried writing onclick=\"retur

相关标签:
4条回答
  • 2021-01-19 13:28

    You can try this CSS

    <style type="text/css" media="print,screen" >
      .unselectable {
         -webkit-touch-callout: none;
         -webkit-user-select: none;
         -khtml-user-select: none;
         -moz-user-select: none;
         -ms-user-select: none;
         user-select: none;
       }
        </style>
    
    <div class="unselectable">
    asdasdsadsadsad<br>asdasdasd
    </div>
    
    <br><br>
    
    <div>
    qqqqqqqqqqqqqqqq<br>asdasdasd
    </div>
    
    0 讨论(0)
  • 2021-01-19 13:33
    <div id="div-test-id" style="width:100px;height:100px;background-color:yellow;">Lorem ipsum</div>
    
    <script type="text/javascript">
    var div_click_escape=function(eventObject){
          return false;
    };
    
    $(function(){
        $("#div-test-id").click(div_click_escape);
        $("#div-test-id").mousedown(div_click_escape);
        $("#div-test-id").mouseup(div_click_escape);
    }
    </script>
    

    Will avoid to select the text.

    0 讨论(0)
  • 2021-01-19 13:37
    document.getElementById('div1').onmousedown = new function ("return false");
    
    0 讨论(0)
  • 2021-01-19 13:42

    If you want to disable selection of the text only, use:

    <div onselectstart='return false;'>
        text
    </div>
    
    div{
       -moz-user-select: none;-webkit-user-select: none;
       -khtml-user-select:none;o-user-select:none;
       user-select: none;
    }
    
    0 讨论(0)
提交回复
热议问题