达到最大长度时更改文本框的焦点 [英] Changing the focus of textbox if it reaches maxlength
问题描述
大家好,
如果一个文本框的长度达到maxlength,则在将焦点更改到另一个文本框时会遇到问题.
如果它是一个普通的asp文本框,它将改变其焦点.但是我使用的是asp文本框,该文本框使用ajax控制工具套件屏蔽了ajax.
我正在使用的代码是
函数changefocus(maxlength)
{
if(document.getElementById(<%= textbox1.ClientID%>").value.length == maxlength)
{
document.getElementById(<%= textbox2.ClientID%>").focus();
}
其他
{
返回;
}
}
当textbox1的长度等于maxlength时,它将清除内容并集中在同一textbox1中,但不会将焦点更改为textbox2.请尽快给我答复解决方案.
谢谢
Hai everyone,
I''m facing issue in changing the focus to another textbox if one textbox length reaches maxlength.
If it is a normal asp textbox it''s changing its focus. But i''m using asp textbox which is masked with ajax using ajax control tool kit.
the code i''m using is
function changefocus(maxlength)
{
if(document.getElementById("<%=textbox1.ClientID%>").value.length==maxlength)
{
document.getElementById("<%=textbox2.ClientID%>").focus();
}
else
{
return;
}
}
When the length of textbox1 is equal to maxlength then it''s clearing the content and focusing back in the same textbox1 but not changing the focus to textbox2. Please reply me the solution ASAP.
Thanks
推荐答案
在您的文本框中,添加 onkeypress JavaScript事件并在其中运行方法:
On your textbox, add an onkeypress JavaScript event and run a method in there:
<script type="text/javascript">
var maxLength = 100;
function CheckLength(textbox) {
if(textbox.value.length >= maxLength) {
document.getElementById("<%=textbox2.ClientID%>").focus();
textbox.value = textbox.value.substring(0, maxLength);
}
}
</script>
<asp:textbox id="textbox1" runat="server" onkeypress="CheckLength() />
<asp:textbox id="textbox2" runat="server" />
这篇关于达到最大长度时更改文本框的焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!