Disabling Textarea from CSS

2019-02-16 08:04发布

In order to disable a textarea (or any other input element), you can:

  • In HTML, you can write: <textarea id='mytextarea' disabled></textarea>

  • From jQuery, you can: $("#mytextarea").attr("disabled","disabled");

  • CSS? Is it possible to disable the textarea with CSS?

7条回答
Melony?
2楼-- · 2019-02-16 08:51

Here is a hack.

<textArea class="tailLog">This page is waiting for something.</textArea>

<script type="text/javascript">
    $(document).ready(  function(){
            $(".tailLog").off().on("keydown", function(event){
                event.preventDefault();
                return;
            });
     });
</script>

The way it works is this. Whenever the user tries to enter anything, we use jquery to catch the event. Then we tell the event we don't want it to do its default behavior. As I say its a hack but its an effective one in a pinch.

查看更多
登录 后发表回答