开发者

Select all string and focus when document is ready

I want to select the input when document is ready. I mean input value must be like highlighted and when I click any button from keyboard input's value should be delete. How can i do this with jquery?

 <input type="text" class="m开发者_如何学CyText" value="First Name"></input>


Give the text box an ID and use the focus and select methods:

<input id="myTextBox" type="text" class="myText" value="First Name"></input>

$(document).ready(function () {
    $("#myTextBox").focus().select();
});

JSFiddle here


By giving input an id

$(document).ready(function(){
    $("#input_id").focus();
    $("#input_id").select();
});

should do it
Best Regards


try it out

$(document).ready(function(){ 

        $('input[type="text"]').focus().select();

        $('input[type="text"]').click(function() {
            $('input[type="text"]').val('');;
        });

    })
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜