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;
});
精彩评论