繁体   English   中英

聚焦功能在这里有什么用? 谁能解释以下代码? 我是一个初学者,所以我需要知道聚焦功能的用法

[英]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

这里需要了解聚焦功能的使用。 谁能解释这个代码?

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()使闪烁的行出现在文本框中,因此您可以开始输入它。 将来尝试首先使用谷歌搜索。

focus()将导致光标显示在该字段中,因此当用户键入内容时,他们将在该字段中键入内容。 这与用户在键入字段之前立即单击该字段时相同。

此代码中的第一个If语句用于验证用户输入的Age是数字,而不是null。 第二个用于检查输入的年龄长度是否大于1(不确定为什么要这样做,但这就是您的声明所要做的)。 对于第一个问题, Focus用于为文本框提供闪烁的光标,即:使其准备好接收用户输入。

在伪代码中,它是:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM