TUTORIAL前端与浏览器FETCHED
Password select() 方法
Password select() 方法 Password 对象 定义和用法 select() 方法用于选取密码域中的文本 语法 passwordObject.select() 浏览器支持 所有主要浏览器都支持 select() 方法 实例 实例 下面的例子可选取密码域中的文本: [mycode2] 菜鸟教程(runoob.com) function myFunction(){ document.g..
更新于 2026/7/16
教程详情页默认 noindex。
Password select() 方法
Password 对象
定义和用法
select() 方法用于选取密码域中的文本
语法
passwordObject.select()
浏览器支持
![]()
![]()
![]()
![]()
![]()
所有主要浏览器都支持 select() 方法
实例
实例
下面的例子可选取密码域中的文本:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script>
function myFunction(){
document.getElementById("pwd").select();
}
</script>
</head>
<body>
<form>
密码: <input type="password" id="pwd" value="thgrt456">
</form>
<button type="button" onclick="myFunction()">选中内容</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script>
function myFunction(){
document.getElementById("pwd").select();
}
</script>
</head>
<body>
<form>
密码: <input type="password" id="pwd" value="thgrt456">
</form>
<button type="button" onclick="myFunction()">选中内容</button>
</body>
</html>
尝试一下 »
Password 对象