如何在javascript中将光标设置为输入框?
问题描述:
document.getElementById(frmObj.id).value="";
document.getElementById(frmObj.id).autofocus;
document.getElementById("errorMsg").innerHTML = "Only numeric value is allowed";
在上面的代码中,表单对象的值完全设置为 但文本框中没有光标。我想要一个光标在那里。 focus()仅关注该输入框但实际上并未设置光标。
In the above code the value of the form object is perfectly setting to "" but there is no cursor in the text box. I want a cursor to be there. focus() only focuses that input box but does not actually set the cursor.
答
在 JavaScript 中首先关注控件,然后选择控件以在texbox上显示光标......
In JavaScript first focus on the control and then select the control to display the cursor on texbox...
document.getElementById(frmObj.id).focus();
document.getElementById(frmObj.id).select();
或使用 jQuery
$("#textboxID").focus();