[removed] cross browser solution for selecting all text inside a textbox on focus

前端 未结 4 1827
一生所求
一生所求 2021-01-12 19:35

I\'m after the following functionality:

  • user clicks on or tabs into a textbox
  • all text in the textbox is selected, unless the textbox already had focu
4条回答
  •  梦谈多话
    2021-01-12 19:40

    You should remember to do a return false; event.stopPropagation(); event.preventDefault() like so:

    $('input[type="text"]').live('click', function (event) {
        this.select();
        event.stopPropagation();
        event.preventDefault();
        return false;
    });
    

    http://jsfiddle.net/7rYLV/

提交回复
热议问题