开发者

How set cursor inside textbox after page load with jquery

开发者 https://www.devze.com 2023-04-09 16:58 出处:网络
Alright i have a asp.net textbox and i want to set cursor inside textbox after page lo开发者_开发百科aded like when you open google.

Alright i have a asp.net textbox and i want to set cursor inside textbox after page lo开发者_开发百科aded like when you open google.

I only need set cursor inside textbox code.

I tried this but not working

$('txtSendTo').focus();


If txtSendTo is an id, you need a #

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


If txtSendTo is a class, you need a .

$('.txtSendTo').focus();


Or, if there is only one textbox on the page

$('textbox').focus();


Also make sure the page is fully loaded before you try to search the dom:

$(document).ready(function () {
  `$('textbox').focus();`
});


I was not able to set cursor inside an input field when a link is clicked. However adding event.preventDefault() at the start of the function and returning false fixed it. Here is the code if someone is having the same issue

$("#search-button").click(function (event) {
  event.preventDefault();
  $("#textbox").focus();
  return false;
});
0

精彩评论

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

关注公众号