简体   繁体   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

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.

相关问题 我正在使用 JS,我知道 replace 方法的用法,你能解释一下下面 function 中的这个具体代码 => /.(?=.{4})/g 吗? - I'm working with JS, I know the use of replace method,Can you explain this specific code => /.(?=.{4})/g in the below function? 谁能解释为什么我收到 map function 错误 - can anyone explain why i'm getting a map function error 如何使用focus函数并在asp.net中调用javascript函数? - how can I use focus function and calling a javascript function in asp.net? 为什么在这里可以使用handleClick函数? - Why can I use handleClick function in here? 谁能在下面的示例中解释此用法? - can anyone explain the use of this in example below? 如何使用函数在此代码上放置输入? 我没有头绪,因为我是初学者 - How can I use function to place inputs on this code? I have no clue because I am a beginner 初学者在这里。 我需要帮助更好地理解这个回调函数 - Beginner here. I need help understanding this callback function better 我不知道这个 function 是如何工作的。 谁能给我解释一下? - I don't know how this function works. Can anyone explain this to me? Number(i) 在下面的代码中被传递到函数中。有人可以解释一下代码中的循环是如何工作的 - Number(i) is passed into the function in the code below.can someone explain how the loops are working in the code 我和0在这做什么? 谁能解释一下? - what is the i and 0 doing here? can anybody explain?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM