如何知道是否在JavaScript中单击并未点击输入

发布于 2025-02-04 01:04:24 字数 299 浏览 2 评论 0原文

我试图弄清楚如何知道何时单击输入以及何时未亮声。让我解释一下:

每当您想在输入字段上键入某些内容时,您就会单击输入框,当您不想键入时,单击其他地方并禁用输入字段。

<input type='text'>

在这里,您可以看到,当您单击它时,该字段将启用,当您单击字段以外的其他地方时,它会禁用。

我只想知道该字段何时被禁用/未亮点。

I'm trying to figure out how to know when an input is clicked and when it is unclicked. Let me explain:

When ever you want to type something on an input field, you click on the input box and when you don't want to type, you click somewhere else and the input field is disabled.

<input type='text'>

Here as you can see, when you click on it, the field is enabled, and when you click somewhere else other than the field, it disables.

I just want to know when the field is disabled/unclicked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热情消退 2025-02-11 01:04:25

我相信您只是在寻找onfocus

<input type='text' onFocus={/* do something */} />

阅读有关React事件的更多信息在这里

I believe you're just looking for onFocus.

<input type='text' onFocus={/* do something */} />

Read more about React events here.

今天小雨转甜 2025-02-11 01:04:24

当您单击输入字段焦点事件时。当您失去焦点模糊时,就会解雇事件。

var elem = document.getElementById("fname")

elem.addEventListener("blur", myFunction);

function myFunction() {
  alert("Input field lost focus.");
}
<input type="text" id="fname">

When you click on the input field focus event is fired. When you lose focus blur event is fired.

var elem = document.getElementById("fname")

elem.addEventListener("blur", myFunction);

function myFunction() {
  alert("Input field lost focus.");
}
<input type="text" id="fname">

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文