HTML DOM Input Password autofocus 属性

WBOY
发布: 2023-08-20 16:17:14
转载
1574人浏览过

html dom input password autofocus属性与html <input>元素的autofocus属性相关联。此属性用于设置或返回在页面加载时输入密码字段是否应自动聚焦。

语法

以下是设置autofocus属性的语法:

设置autofocus属性 -

passwordObject.autofocus = true|false
登录后复制

在这里,true表示密码字段应该获得焦点,false表示否。默认情况下设置为false。

示例

让我们来看一个关于Input Password autofocus属性的例子 -

立即学习前端免费学习笔记(深入)”;

<!DOCTYPE html>
<html>
<body>
<h1>Input password autofocus property</h1>
Password: <input type="password" id="PASS" autofocus>
<br><br>
<button onclick="FocusVal()">CHECK FOCUS</button>
<p id="Sample"></p>
<script>
   function FocusVal() {
      var P = document.getElementById("PASS").autofocus;
      document.getElementById("Sample").innerHTML = "The password field has autofocus property set to "+P;
   }
</script>
</body>
</html>
登录后复制

输出

这将产生以下输出 −

HTML DOM Input Password autofocus 属性

在点击CHECK FOCUS按钮时 −

HTML DOM Input Password autofocus 属性

在上面的示例中 −

我们创建了一个类型为“password”的输入字段,id为“Pass”,并启用了自动对焦属性,即设置为true −

Password: <input type="password" id="PASS" autofocus>
登录后复制

我们接下来创建了一个按钮 CHECK FOCUS,当用户点击时将执行 FocusVal() 方法 −

<button onclick="FocusVal()">CHECK FOCUS</button>
登录后复制

The FocusVal() method gets the input element with type password using the getElementById() method and gets its autofocus property. The autofocus property returns true and false depending on the element autofocus attribute value. This value is assigned to variable P and displayed in the paragraph with id “Sample” using its innerHTML property −

function FocusVal() {
   var P = document.getElementById("PASS").autofocus;
   document.getElementById("Sample").innerHTML = "The password field has autofocus property set to "+P;
}
登录后复制

以上就是HTML DOM Input Password autofocus 属性的详细内容,更多请关注php中文网其它相关文章!

WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号