如何在切换到下一个输入文本后自动触发输入按钮(how to automatic trigger the enter button after switching to next input text)

编程入门 行业动态 更新时间:2024-10-27 12:27:16
如何在切换到下一个输入文本后自动触发输入按钮(how to automatic trigger the enter button after switching to next input text)

你好我需要在用户切换到另一个html input type='text'后自动触发输入按钮。 我需要这样做,以便我可以验证表单。

这里是我的代码:

<input type="text" class="form-control input-sm" name="student_lastname" placeholder="Last Name" pattern="[A-Za-z].{1,}" title="Only Letters are accepted and more than 1 letter" required>

我需要错误title="Only Letters are accepted and more than 1 letter"弹出时,用户完成键入框

现在这是我的代码看起来像

hello guys i need to automatic trigger the enter button after the user switch to another html input type='text'. i need to do this so that i can validate the form.

here is my code:

<input type="text" class="form-control input-sm" name="student_lastname" placeholder="Last Name" pattern="[A-Za-z].{1,}" title="Only Letters are accepted and more than 1 letter" required>

i need the error title="Only Letters are accepted and more than 1 letter" to pop up when the user is finished typing to the box

right now this is what my code looks like

最满意答案

onblur是完美的解决方案,专为用户离开输入字段时制定。 只要做这样的事情:

对于HTML:

<input type="text" onblur="validate()" />

对于JS:

function validate() { // This is how you automatically make them click the Enter button: enterButton.click(); }

onblur is the perfect solution, and was made specifically for when the user leaves an input field. Just do something like this:

For HTML:

<input type="text" onblur="validate()" />

And for JS:

function validate() { // This is how you automatically make them click the Enter button: enterButton.click(); }

更多推荐

type,需要,代码,user,letter,电脑培训,计算机培训,IT培训"/> <meta name="descri

本文发布于:2023-08-06 04:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444852.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:切换到   按钮   文本   如何在   automatic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!