How to make readonly textbox using Jquery

Sometimes making a textbox readonly is project need. There are 2 ways to make textbox readonly using jQuery.

Method 1:
<script type="text/javascript">
   $(document).ready(function(){
      $("#<%=txtName.ClientID %>").focus(function () {
             $(this).blur();
      });
   });
</script>
See live Demo and Code
Method 2:
<script type="text/javascript">
   $(document).ready(function(){
      $("#<%=txtName.ClientID %>").attr('readonly', true);
   });
</script>
Feel free to contact me for any help related to jQuery. I will gladly help you.
SHARE

Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience. I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect..