Password readOnly 属性
 Password 对象
 Password 对象
定义和用法
readOnly 属性可设置或返回密码域是否为只读。
只读字段不能被修改。但是,用户可以选中它并复制文本。
语法
设置 readOnly 属性:
passwordObject.readOnly=true|false
返回 readOnly 属性:
passwordObject.readOnly
浏览器支持





所有主要浏览器都支持 readOnly 属性
实例
实例
下面的例子把密码域设置为只读:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>代码学院(codexy.cn)</title>
<script>
function setResult(){
document.getElementById("pwd").readOnly=true;
}
</script>
</head>
<body>
<form>
密码: <input type="password" id="pwd">
</form>
<button type="button" onclick="setResult()">设置只读</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>代码学院(codexy.cn)</title>
<script>
function setResult(){
document.getElementById("pwd").readOnly=true;
}
</script>
</head>
<body>
<form>
密码: <input type="password" id="pwd">
</form>
<button type="button" onclick="setResult()">设置只读</button>
</body>
</html>
尝试一下 »
 Password 对象
 Password 对象			
						
			
 JavaScript 教程
JavaScript 教程 JavaScript 对象
JavaScript 对象 jQuery 教程
jQuery 教程 JSON 教程
JSON 教程 AngularJS 教程
AngularJS 教程 Angular 2 教程
Angular 2 教程 Vue.js 教程
Vue.js 教程 React 教程
React 教程 jQuery UI 教程
jQuery UI 教程 jQuery EasyUI 教程
jQuery EasyUI 教程 AJAX 教程
AJAX 教程 Highcharts 教程
Highcharts 教程 Google Maps API 教程
Google Maps API 教程 ES6 教程
ES6 教程 TypeScript教程
TypeScript教程 ES6 标准入门
ES6 标准入门