<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
编写实现获取焦点时效果的代码
<body>
<input type='text' value='手机' style='color:#999'>
</body>
<script>
var text = document.querySelector('input');
text.onfocus = function() {
if (this.value === '手机') {
this.value = '';
}
this.style.color = '#333';
};
编写失去焦点效果时的效果代码
text.onblur = function () {
if (this.value === '') {
this.value = '手机';
}
this.style.color = '#999'
};
</script>
</html>
实现前的样式
实现后的样式且框内带有闪动的竖杠样式