JavaScript基础学习 显示隐藏文本框内容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=devcie-width,initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
input {
color: #999;
}
</style>
</head>
<body>
<input type="text" value="手机">
<script>
var inpt = document.querySelector('input');
inpt.onfocus = function() {
console.log('得到焦点');
if (inpt.value === '手机') {
inpt.value = '';
inpt.style.color = '#333';
}
}
inpt.onblur = function() {
console.log('失去焦点');
if (inpt.value === '') {
inpt.value = '手机';
inpt.style.color = '#999';
}
}
</script>
</body>
</html>