嗨,大家好,有人可以告诉我如何使用JavaScript来关注HTML文本框? 我是编程的总新手,刚开始学习。我在这里代码 我想在文本框中设置光标。如何使用javascript关注html文本框?
的test.html
<html>
<head>
<script type='text/javascript'>
function parseTest() {
var elem_1 = document.getElementById('input_1');
var elem_2 = document.getElementById('input_2');
var inp_1 = elem_1.value;
var inp_2 = elem_2.value;
if (inp_1 == "" && inp_2 == "") {
alert("You need to enter integers!!!");
elem_1.focus();
}else if (inp_1 == ""){
alert("You need to enter Integer 1!!!");
elem_1.focus();
}else if (inp_2 == ""){
alert("You need to enter Integer 2!!!");
elem_2.focus();
}else {
if (!parseInt(inp_1) || !parseInt(inp_2)) alert ("Enter Integers only!!!");
else alert("Correct Inputs!!!");
}
}
</script>
</head>
<body>
<form name="myform">
<input type="text" id="input_1" name="input_1" /><br />
<input type="text" id="input_2" name="input_2" /><br />
<input type="submit" value="Check!" onclick="parseTest();" />
</form>
</body>
</html>
我是一个新手,总那么请耐心等待。请帮助...
您的代码__will__将重点放在输入框......究竟是什么问题? – ampersand 2011-05-02 08:39:31
你说了一些关于焦点的内容,稍后你会说一些关于将光标置于文本框顶部的内容,您想要实现哪些内容? – Ruben 2011-05-02 08:39:46
我的意思是在文本域 – 2011-05-02 08:42:04