[英]How do I move the cursor from the first textarea to a second textarea, without using tab or the mouse?
我正在建立一個包含三個文本區域的密碼框。 每個文本區域都有一個字符。 輸入密碼的第一個字符后,我必須按tab或使用鼠標移至第二個文本區域以輸入密碼的第二個字符。 我想在輸入第一個文本區域后立即自動進行此操作(光標移動)。
我怎樣才能做到這一點?
如果您可能要問,我正在C#中使用Visual Studio .NET 2008,我是.net中的完美新手,而且我不知道如何用合適的詞問這個問題。
謝謝。
嘗試onKeyPress 。 那應該照顧您想要的東西。
<input type="text" name="password" onKeyPress="autoTab()" />
<script type="text/javascript" language="JavaScript">
function autoTab() {
//do stuff
}
</script>
這是一個處理字段的光標位置的教程。
http://www.webdeveloper.com/forum/showthread.php?t=91817
這表明您的autoTab()函數應如下所示。
function autoTab(field,nextFieldID){
if(field.value.length >= field.maxLength){
document.getElementById(nextFieldID).focus();
}
}
您在項目中使用jQuery嗎?
<!DOCTYPE html>
<html>
<head>
<title>example</title>
<style type="text/css">
*
{
margin: 0;
padding: 0;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#data1').keyup(function () {
if ($(this).val().length == 1) {
$('#data2').focus();
}
});
});
</script>
</head>
<body>
<input id="data1" type="text" value="" style="width: 10px" /><br />
<input id="data2" type="text" value="" style="width: 10px" />
</body>
</html>
if textbox1.text.length > 0 then textbox2.focus();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.