📅  最后修改于: 2020-11-26 06:58:32             🧑  作者: Mango
jQuery焦点事件在元素获得焦点时发生。它是通过鼠标单击或导航到它来生成的。
此事件隐式用于有限的元素集,例如表单元素,
聚焦方法通常与blur()方法一起使用。
句法:
$(selector).focus()
它触发选定元素的焦点事件。
$(selector).focus(function)
它为焦点事件添加了一个函数。
Parameter | Description |
---|---|
Function | It is an optional parameter. It is used to specify the function to run when the element gets the focus. |
让我们以一个示例来演示jQuery focus()事件。
focus demo
Focus starts.. Write your name.
Focus starts.. Write your password.
输出:
如果要阻止人们在上面的示例中在文本输入框中书写,请尝试以下代码。
它将禁止在文本框中写入。
focus demo