[英]what is the use of focus function here ? can anyone explain the below code? i'm a beginner so i need to know the use of focus function
Need to know the use of focus function here. 这里需要了解聚焦功能的使用。 Can anyone explain this code?
谁能解释这个代码?
function Allow Age(){
if(!form.age.value.match(/[0-9]+$/) && form.age.value !="")
{
form.age.value="";
form.age.focus();
alert("invalid format");
}
if(form.age.value.length > 1)
alert("invalid entry")
}
.focus()
makes the blinking line appear in the text box so you can start typing in it. .focus()
使闪烁的行出现在文本框中,因此您可以开始输入它。 Try googling it first in future. 将来尝试首先使用谷歌搜索。
focus()
will cause the cursor to show up in that field so when the user types, they type into that field. focus()
将导致光标显示在该字段中,因此当用户键入内容时,他们将在该字段中键入内容。 It is the same as when the user clicks on the field right before typing into it. 这与用户在键入字段之前立即单击该字段时相同。
The first If statement in this code is to validate that the Age entered by the user is numerical, and not null. 此代码中的第一个If语句用于验证用户输入的Age是数字,而不是null。 The second is used to check if length of entered age is greater than 1 (Not sure why you have this, but this is what your statement does).
第二个用于检查输入的年龄长度是否大于1(不确定为什么要这样做,但这就是您的声明所要做的)。 As for your first question, Focus is used to give the textbox the blinking cursor, ie : Set it ready for receiving user input.
对于第一个问题, Focus用于为文本框提供闪烁的光标,即:使其准备好接收用户输入。
In pseudo code, it is : 在伪代码中,它是:
function Allow Age(){
If age is not numeric and its value is not null
Clear the textbox
Set focus to the textbox
Send a message saying "Invalid format"
End if
If the length of the age entered is greater than 1
Send a message saying "Invalid Entry"
End if
}
这意味着form
中的age
字段将获得输入焦点 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.