完成清除后如何移动上一个文本框? [英] How to move previous textbox when finish clear ?

查看:66
本文介绍了完成清除后如何移动上一个文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hsi Everyone

我在网站上有网上注册,所以我使用六个html输入类型的文本框,如果第一个文本框有4个字母自动移动到下一个文本框到最后一个文本我已经完成以下代码

Hsi Everyone
I have online registration in website,so i use six html input type text boxes,i have completed if first text box have 4 letters automatically move to next text box up to last text and below that code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript to automatically move from one field to another field</title>
<script type="text/javascript">
function movetoNext(current, nextFieldID) {
if (current.value.length >= current.maxLength) {
document.getElementById(nextFieldID).focus();
}
}
</script>
</head>
<body>
Enter your Text:
<input type="text" id="first" size="4" onkeyup="movetoNext(this, 'second')" maxlength="3" />
<input type="text" id="second" size="4" onkeyup="movetoNext(this, 'third')" maxlength="3" />
<input type="text" id="third" size="5" maxlength="4" />
</body>
</html>





我的下一个要求是如果在所有文本框中错误输入序列号,用户可以通过任何文本框中的退格清除该值,如果文本框自动清除移动到上一个字符中的上一个文本框。像上面的代码中的movetoNext()函数,就像我想要一个函数movetoPrevious()函数移动到最后一个字母中的上一个文本框所以可以使用baskspace清除文本。

注意:只使用退格键,支持所有浏览器,如ie8,ie9,mozila和ch罗马



请尽快回复

问候

Aravind



my next requirement is if wrongly enter serial number in all text box,user clear that value by using 'Backspace' from any text box,if text box clear automatically move to previous text box in last character .same like movetoNext() function above in code,like that i want one function movetoPrevious() function for move to previous text box in last letter so can clear text by using baskspace.
Note:only use backspace button ,support for all browser also like ie8,ie9,mozila and chrome

Pls reply asap
Regards
Aravind

推荐答案

我有一些代码给你

js

I have some code for you
js
function move(txt) {

           var value = txt.value;
           var length = txt.value.length

           if (length == 0) {


(txt).prev()。focus();
return false ;
}
其他 如果(长度> 4 ){
(txt).prev().focus(); return false; } else if (length > 4) {


(txt).next()。focus()。val(value.substr( 4 1 ));
(txt).next().focus().val(value.substr(4, 1));


这篇关于完成清除后如何移动上一个文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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