开发者

how to select the content of a focused text

开发者 https://www.devze.com 2023-02-23 06:30 出处:网络
I have a <input type=\"text\" 开发者_如何学JAVAvalue=\"Hi! Enter Here\" > How to open this in selected mode and cursor on the input field.

I have a <input type="text" 开发者_如何学JAVAvalue="Hi! Enter Here" >

How to open this in selected mode and cursor on the input field.

We just start writting into it


use jquery focus() function

$('input').focus();

Or better

<input type="text" value="Hi! Enter Here" id="someid">

and

$('#someid').focus();

check working example here.

For select and focus

$('#someid').focus().select();

or

$('#someid').focus(function (){$(this).select();});

On jsfiddle.net


$("input").focus(); 

Read more at http://api.jquery.com/focus/


Set the id of the input

<input type="text" id="myText" value="Hi! Enter Here" >

Then add this jQuery

$(function() {
  $("#myText").focus();
});
0

精彩评论

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