世纪佳缘 用户名 显示隐藏内容
功能描述
- 表单框默认内容为“邮箱/ID/手机号”;颜色较浅。
- 鼠标放到表单框时,内容清空,边框颜色变为粉色。输入内容颜色较深。
- 鼠标离开,如果输入有内容则保留原有输入内容;没有输入内容则改回默认内容。颜色较浅。
代码实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input {
color: #999;
border: 1px solid #999;
}
</style>
</head>
<body>
<input type="text" value="邮箱/ID/手机号">
<script>
var ipt = document.querySelector('input')
ipt.onfocus = function() {
if (this.value === '邮箱/ID/手机号') {
this.value = '';
}
this.style.color = '#333';
this.style.borderColor = 'pink'
this.style