如何在javascript中将光标设置为输入框? [英] how to set cursor to input box in javascript?

查看:119
本文介绍了如何在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();

这篇关于如何在javascript中将光标设置为输入框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆